Use a NonZeroUsize to store the prefix buffer length

This commit is contained in:
Kerollmops 2025-04-21 18:50:28 +02:00
parent 44586e089d
commit 8d9eb2a7c4
No known key found for this signature in database
GPG Key ID: F250A4C4E3AE5F5F

View File

@ -1,6 +1,7 @@
use std::cell::RefCell;
use std::collections::BTreeSet;
use std::io::{BufReader, BufWriter, Read, Seek, Write};
use std::num::NonZeroUsize;
use hashbrown::HashMap;
use heed::types::Bytes;
@ -217,7 +218,7 @@ impl WordPrefixIntegerDocids {
index.push(PrefixIntegerEntry {
prefix,
pos,
serialized_length: Some(buffer.len()),
serialized_length: NonZeroUsize::new(buffer.len()),
});
file.write_all(buffer)?;
}
@ -243,7 +244,7 @@ impl WordPrefixIntegerDocids {
key_buffer.extend_from_slice(&pos.to_be_bytes());
match serialized_length {
Some(serialized_length) => {
buffer.resize(serialized_length, 0);
buffer.resize(serialized_length.get(), 0);
file.read_exact(&mut buffer)?;
self.prefix_database.remap_data_type::<Bytes>().put(
wtxn,
@ -266,7 +267,7 @@ impl WordPrefixIntegerDocids {
struct PrefixIntegerEntry<'a> {
prefix: &'a str,
pos: u16,
serialized_length: Option<usize>,
serialized_length: Option<NonZeroUsize>,
}
/// TODO doc