Crates.io | german-str |
lib.rs | german-str |
version | 0.1.0 |
source | src |
created_at | 2024-08-20 13:27:00.812388 |
updated_at | 2024-08-20 13:27:00.812388 |
description | small-string optimized string type with fast comparisons |
homepage | |
repository | https://github.com/ostnam/german-str |
max_upload_size | |
id | 1345245 |
size | 49,259 |
German strings are a string type with the follow properties:
size_of::<GermanStr>() == 16
They are described here. TL;DR: it's a 16 bytes struct where:
u32
representing the length of the string.The implementation was heavily inspired by SmolStr
.
The main downside of GermanStr
compared to SmolStr
is that heap buffers aren't shared between instances by default: this is enabled by calling leaky_shared_clone
, which clones in O(1) time, but introduces the risks associated with manual memory management.
[cfg(target_pointer_width = "64")]
[no_std]
.The following plots are generated by the crate's benchmarks. In the first half of rows, comparisons are made on random ASCII strings. As a result, the vast majority of comparisons only require comparing prefixes.
In the second half (worst cases), the string compared are identical, and every pair of byte has to be compared. Unless the string is short enough to be inlined, performance is equivalent to comparing two regular String
.