diff options
author | Vincent Ambo <mail@tazj.in> | 2024-08-16T17·14+0300 |
---|---|---|
committer | tazjin <tazjin@tvl.su> | 2024-08-19T13·19+0000 |
commit | 2284c00417260c3aebb9f022629ded9a64a9ca7e (patch) | |
tree | 2ef976699e56feeaa9723ea8abff29fd8f393400 /users | |
parent | 0714184b1fb74e7bd7f685ace098aacb07387edc (diff) |
feat(tazjin/german-string): PartialEq implementation for GermanString r/8528
This is where one of the advantages of this string representation starts to shine: For small strings there's no derefencing any heap memory at all, and for the long representation we can compare the prefix before moving on. Change-Id: Iac333a52e8d7c9dd09e33dbcf51754e321c880e6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12238 Reviewed-by: tazjin <tazjin@tvl.su> Autosubmit: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'users')
-rw-r--r-- | users/tazjin/german-string/src/lib.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/users/tazjin/german-string/src/lib.rs b/users/tazjin/german-string/src/lib.rs index eb6d02f29131..cf315c9d5dce 100644 --- a/users/tazjin/german-string/src/lib.rs +++ b/users/tazjin/german-string/src/lib.rs @@ -100,6 +100,22 @@ impl Drop for GermanString { } } +impl PartialEq for GermanString { + fn eq(&self, other: &GermanString) -> bool { + if self.len() != other.len() { + return false; + } + + unsafe { + if self.len() <= 12 { + return self.0.small.data[..self.len()] == other.0.small.data[..other.len()]; + } + return self.0.large.prefix == other.0.large.prefix + && self.as_bytes() == other.as_bytes(); + } + } +} + #[cfg(test)] mod tests { use super::*; |