Skip to content

Commit 9d2925b

Browse files
perf(matcher): store haystacks as Box<str>
Saves 8 bytes of header per entry
1 parent 94e4136 commit 9d2925b

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

television/matcher/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ fn matched_item<I: Sync + Send + Clone + 'static>(
414414

415415
MatchedItem::new(
416416
store.items[index as usize].clone(),
417-
haystack.clone(),
417+
haystack.to_string(),
418418
// Convert UTF-8 byte offsets to UTF-32 character indices
419419
byte_indices_to_char_indices(haystack, match_indices),
420420
)

television/matcher/worker.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub(super) struct Store<I> {
3232
/// Items that have been added to the matcher.
3333
pub(super) items: Vec<I>,
3434
/// The strings the items are matched against.
35-
pub(super) haystacks: Vec<String>,
35+
pub(super) haystacks: Vec<Box<str>>,
3636
}
3737

3838
impl<I> Default for Store<I> {
@@ -308,7 +308,7 @@ where
308308
store.haystacks.reserve(batch.len());
309309
for (item, haystack) in batch {
310310
store.items.push(item);
311-
store.haystacks.push(haystack);
311+
store.haystacks.push(haystack.into_boxed_str());
312312
}
313313
true
314314
}

0 commit comments

Comments
 (0)