You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
1. When a non-trivial slice is under 31 bytes, it is held entirely in the remainder word.
Rationale: there are enough cases where this is essential for it to be the default for all cases.
For example, for byte-arrays with empty data arrays and spans from short-strings (to be implemented)
it is essential, and for slices inside the data array that don't end in a word boundary moving
the slice into remainder simplifies handling.
2. For slices over 31 bytes that end inside the remainder word or end at a data-word boundary
(meaning the last byte is at index 30 of one of the cells of `data`), we slice the data
accordingly and adjust the start offset.
3. For slices over 31 bytes that end in the data span before the word boundary (meaning they end at
an index k < 30), we pop the last word from the data span and move into the remainder word,
which creates a similar representation as in (2) above.
Invariants: In all slices above, the following hold:
- data array always contains full bytes31 (like ByteArray) with the exception of
the first word, that can have a start-offset (the remainder of the offset is masked in `into` before
passing into ByteArray).
- The optional remainder word always starts at the word boundary: in other words, the remainder word
never has a start-offset, only a negative offset (`remainder_word_len`). This simplifies the logic
and is a more consistent representation of a slice.
Possible optimizations:
- Perform the slice_bytes31 calls lazily in `into` instead of in `slice`: this improves slices at
the cost of `into`, which is worth it performance-wise. However, this makes the logic more
complicated and the byte-span representation less strict. For example, we can relax the
relaxation on remainder-word not having start-offset for <= 31 sized words, and only slice it
at `into`.
- Optimize slice_bytes31: split both ends at once instead of calling split_bytes31 twice, without
having to duplicate `split_bytes31` logic.
0 commit comments