A LimitArray is like an array, except it contains 2 pointers, "ptr" and "limit",
instead of a "ptr" and "length".
The first pointer, "ptr", points to the beginning (like a normal array) and the
second pointer, "limit", points to 1 element past the last element in the array.
-------------------------------
| first | second | ... | last |
-------------------------------
^ ^
ptr limit
`
To get the length of the LimitArray, you can evaluate limit - ptr.
To check if a LimitArray is empty, you can check if ptr == limit.
The reason for the existense of the LimitArray structure is that some functionality
is more efficient when it uses this representation. A common example is when processing
or parsing an array of elements where the beginning is iteratively "sliced off" as
it is being processed, i.e. array = array[someCount .. $]; This operation is more efficient
when using a LimitArray because only the "ptr" field needs to be modified whereas a normal array
needs to modify the "ptr" field and the "length" each time. Note that other operations are more
efficiently done using a normal array, for example, if the length needs to be evaluated quite
often then it might make more sense to use a normal array.
In order to support "Element Type Modifiers" on a LimitArray's pointer types, the types are
defined using a template. Here is a table of LimitArray types with their equivalent normal array types.
TODO: move this to the mored repository
A LimitArray is like an array, except it contains 2 pointers, "ptr" and "limit", instead of a "ptr" and "length".
The first pointer, "ptr", points to the beginning (like a normal array) and the second pointer, "limit", points to 1 element past the last element in the array.
To get the length of the LimitArray, you can evaluate limit - ptr. To check if a LimitArray is empty, you can check if ptr == limit.
The reason for the existense of the LimitArray structure is that some functionality is more efficient when it uses this representation. A common example is when processing or parsing an array of elements where the beginning is iteratively "sliced off" as it is being processed, i.e. array = array[someCount .. $]; This operation is more efficient when using a LimitArray because only the "ptr" field needs to be modified whereas a normal array needs to modify the "ptr" field and the "length" each time. Note that other operations are more efficiently done using a normal array, for example, if the length needs to be evaluated quite often then it might make more sense to use a normal array.
In order to support "Element Type Modifiers" on a LimitArray's pointer types, the types are defined using a template. Here is a table of LimitArray types with their equivalent normal array types.
| Normal Array | Limit Array | |---------------------|-------------------------| | char[] | LimitArray!char.mutable LimitArray!(const(char)).mutable LimitArray!(immutable(char)).mutable | | const(char)[] | LimitArray!char.const LimitArray!(const(char)).const LimitArray!(immutable(char)).const | | immutable(char)[] | LimitArray!char.immutable LimitArray!(const(char)).immutable LimitArray!(immutable(char)).immutable |