Skip allocations

This commit is contained in:
Antoine Gersant 2024-09-21 19:44:35 -07:00
parent 5e8587c39f
commit 81403960b0

View file

@ -6,6 +6,7 @@ use std::{
ffi::OsStr,
path::{Path, PathBuf},
};
use tinyvec::TinyVec;
use crate::app::{
index::{
@ -136,7 +137,7 @@ struct TextFieldIndex {
impl TextFieldIndex {
pub fn insert(&mut self, raw_value: &str, value: Spur, key: SongKey) {
// TODO sanitize ngrams
let characters = raw_value.chars().collect::<Vec<_>>();
let characters = raw_value.chars().collect::<TinyVec<[char; 32]>>();
for substring in characters[..].windows(NGRAM_SIZE) {
self.ngrams
.entry(substring.try_into().unwrap())