Experiment with pointer-based slice prefix computation in normalizer #2433
Labels
A-performance
Area: Performance (CPU, Memory)
C-collator
Component: Collation, normalization
S-small
Size: One afternoon (small bug fix or enhancement)
Milestone
#2378 uses a pattern where there is a full slice and another slice that's known to be its suffix, and the prefix of the full slice is computed either so that the suffix is excluded or the suffix and a number of code units before the suffix is excluded.
Currently, this is done by taking the length of the full slice and subtracting the length of the suffix slice. However, in practice, the suffix slice comes from
as_slice()
/as_str()
on a by-char
iterator. The iterator may not actually store the length internally. Whether or not the iterator actually stores the length, it does store its start pointer.It could be a tiny bit more efficient to compute the prefix length from the pointer distance. Done in the pointer domain, this requires
unsafe
. By casting the pointers tousize
, this can be done in safe code. It's unclear to me if real optimization opportunities are lost by casting away pointerness before subtracting.The text was updated successfully, but these errors were encountered: