Mica::Core::ByteScan
Byte-run scanning and copying for the hot paths of format scanners and trees (text runs, attribute values, names, stored values).
This is the one place in Mica that touches bytes without a bounds check
on every access: each method checks its whole window against the slice
once, before it reads or writes, and never leaves that window.
Everything else goes through checked Slice indexing.
Class methods
Copies all of source into target starting at offset, without
building a subslice. Raises IndexError unless
0 <= offset <= target.size - source.size, and when target is
read-only.
target = Bytes.new(4)
Mica::Core::ByteScan.copy_into(target, 1, "ab".to_slice)
target # => Bytes[0, 97, 98, 0]
Returns true when the expected.size bytes of bytes at offset
equal expected. Raises IndexError unless
0 <= offset <= bytes.size - expected.size. Compares in place, which
beats building a slice and calling memcmp for short names.
Mica::Core::ByteScan.matches?("<a></a>".to_slice, 5, "a".to_slice) # => true
Returns the index of the first byte in bytes[from...stop] for which
the block returns false, or stop when it returns true for all of
them. Raises IndexError unless 0 <= from <= stop <= bytes.size.
Mica::Core::ByteScan.skip_while("abc;d".to_slice, 0, 5) { |byte| byte != ';'.ord } # => 3