core: use memchr for trunc_key_at0
This commit is contained in:
parent
3758f94b03
commit
afaa250026
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -157,6 +157,12 @@ version = "0.1.4"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f051f77a7c8e6957c0696eac88f26b0117e54f52d3fc682ab19397a8812846a4"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.5.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d"
|
||||
|
||||
[[package]]
|
||||
name = "memmap2"
|
||||
version = "0.5.8"
|
||||
|
@ -426,6 +432,7 @@ name = "yglnk-core"
|
|||
version = "0.0.1"
|
||||
dependencies = [
|
||||
"int-enum",
|
||||
"memchr",
|
||||
"xxhash-rust",
|
||||
]
|
||||
|
||||
|
|
|
@ -12,6 +12,10 @@ license = "Apache-2.0 OR ISC"
|
|||
version = "0.5"
|
||||
default-features = false
|
||||
|
||||
[dependencies.memchr]
|
||||
version = "2.5"
|
||||
default-features = false
|
||||
|
||||
[dependencies.xxhash-rust]
|
||||
version = "0.8"
|
||||
features = ["xxh64"]
|
||||
|
|
|
@ -158,7 +158,7 @@ impl<'a> Ref<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
return None;
|
||||
None
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> Iter<'a> {
|
||||
|
|
|
@ -74,8 +74,9 @@ pub enum Ntt01 {
|
|||
}
|
||||
|
||||
pub fn trunc_key_at0(key: &[u8]) -> &[u8] {
|
||||
let key_end = key.iter().take_while(|&&i| i != 0).count();
|
||||
&key[..key_end]
|
||||
memchr::memchr(0, key)
|
||||
.map(|key_end| &key[..key_end])
|
||||
.unwrap_or(key)
|
||||
}
|
||||
|
||||
pub fn decode_location(location: u32) -> Option<usize> {
|
||||
|
|
Loading…
Reference in a new issue