Skip to content

Trivial Indices #6

Description

@GregYannes

In commit 4454085 we added a Case 0 to Arr_IndexRaw() for when l > u

Idx/src/Idx.bas

Lines 200 to 202 in f05dcb3

Select Case n
Case 0: Assign v, a()
Case 1: Assign v, a(i(l))

…along with a Case Else:

Idx/src/Idx.bas

Lines 262 to 263 in f05dcb3

Case Else: Assign v, a()
End Select

This addresses any situation where the bounds are discoordinated, and throws the native error for trying to access an array without supplying any indices: a().


However, it also adds one extra Case every time we access an array. I suspect we would be just as safe removing Case 0

Idx/src/Idx.bas

Lines 215 to 216 in 9cf1fec

Select Case n
Case 1: Assign v, a(i(l))

…and simply deferring to the Case Else. Unless I misinterpret the Select Case statement, we (linearly) gain a little performance for all other situations, by skipping the irrelevant Case 0.

Only when the array is uninitialized do we have l > u, and we must traverse all sixty cases from Case 1 through Case 60, before we reach the Case Else. But Arr_Index() already validates against this situation…

Idx/src/Idx.bas

Lines 124 to 126 in f05dcb3

' Short-circuit for uninitialized array.
Dim aRnk As Long: aRnk = Arr_Rank(arr)
If aRnk = 0 Then Debug.Print "ERROR: The array must be initialized."

…as does Arr_IndexRaw():

Idx/src/Idx.bas

Lines 161 to 163 in f05dcb3

' Short circuit for uninitialized array.
Dim r As Long: r = Arr_Rank(x)
If r = 0 Then Debug.Print "ERROR: Uninitialized array."

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions