Skip to content

could firstindex be changed to return isbits for the AbstractArray subtypes defined in Base #57636

@nsajko

Description

@nsajko

I often assume the arr[begin] indexing syntax is a zero-cost abstraction, assuming arr is known to use one-based indexing at compile time. However, the begin is actually firstindex(arr), which returns heavy types like BigInt, which relies on ccall a lot, in some cases:

julia> typeof(firstindex(big(1000):big(3000)))
BigInt

julia> typeof(firstindex(Base.OneTo(big(3000))))
BigInt

AFAIK all the concrete AbstractArray subtypes defined in Base use one-based indexing, so it seems like it should be OK for firstindex(arr) to just return 1 (of type Int) for any concrete type that comes by default with Julia.

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]performanceMust go fasterrangesEverything AbstractRange

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions