feat(tazjin/german-string): PartialEq implementation for GermanString

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
This commit is contained in:
Vincent Ambo 2024-08-16 20:14:34 +03:00 committed by tazjin
parent 0714184b1f
commit 2284c00417

View file

@ -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::*;