Skip to content

Experiment with pointer-based slice prefix computation in normalizer #2433

Open
@hsivonen

Description

@hsivonen

#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 to usize, this can be done in safe code. It's unclear to me if real optimization opportunities are lost by casting away pointerness before subtracting.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-performanceArea: Performance (CPU, Memory)C-collatorComponent: Collation, normalizationS-smallSize: One afternoon (small bug fix or enhancement)

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions