Use an ugly trick to avoid cloning the FST

This commit is contained in:
Clément Renault 2019-12-20 17:39:32 +01:00
parent 1163f390b3
commit 4be11f961b
No known key found for this signature in database
GPG key ID: 0151CDAB43460DAE
2 changed files with 12 additions and 1 deletions

View file

@ -67,6 +67,17 @@ impl Main {
self.main.put::<_, Str, ByteSlice>(writer, WORDS_KEY, bytes)
}
pub unsafe fn static_words_fst(self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<fst::Set>> {
match self.main.get::<_, Str, ByteSlice>(reader, WORDS_KEY)? {
Some(bytes) => {
let bytes: &'static [u8] = std::mem::transmute(bytes);
let set = fst::Set::from_static_slice(bytes).unwrap();
Ok(Some(set))
}
None => Ok(None),
}
}
pub fn words_fst(self, reader: &heed::RoTxn<MainT>) -> ZResult<Option<fst::Set>> {
match self.main.get::<_, Str, ByteSlice>(reader, WORDS_KEY)? {
Some(bytes) => {