From 4be11f961b624dcd027d7c799dbd5a48c46fd083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Fri, 20 Dec 2019 17:39:32 +0100 Subject: [PATCH] Use an ugly trick to avoid cloning the FST --- meilisearch-core/src/bucket_sort.rs | 2 +- meilisearch-core/src/store/main.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/meilisearch-core/src/bucket_sort.rs b/meilisearch-core/src/bucket_sort.rs index a0609d30d..f173c2955 100644 --- a/meilisearch-core/src/bucket_sort.rs +++ b/meilisearch-core/src/bucket_sort.rs @@ -446,7 +446,7 @@ fn fetch_matches<'txn, 'tag>( ) -> MResult>> { let before_words_fst = Instant::now(); - let words = match main_store.words_fst(reader)? { + let words = match unsafe { main_store.static_words_fst(reader)? } { Some(words) => words, None => return Ok(Vec::new()), }; diff --git a/meilisearch-core/src/store/main.rs b/meilisearch-core/src/store/main.rs index 0efdd140e..90c662db4 100644 --- a/meilisearch-core/src/store/main.rs +++ b/meilisearch-core/src/store/main.rs @@ -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) -> ZResult> { + 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) -> ZResult> { match self.main.get::<_, Str, ByteSlice>(reader, WORDS_KEY)? { Some(bytes) => {