Skip to content

Commit 82874cd

Browse files
committed
Optimize Yarn instantiation
Thanks to @mcy for the suggestion!
1 parent 3d60c02 commit 82874cd

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

gix-attributes/src/search/outcome.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bstr::{BString, ByteSlice};
2-
use byteyarn::Yarn;
2+
use byteyarn::YarnBox;
33
use gix_glob::Pattern;
44

55
use crate::{
@@ -59,7 +59,7 @@ impl Outcome {
5959
self.selected.clear();
6060
self.selected.extend(attribute_names.map(|name| {
6161
(
62-
Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
62+
YarnBox::new(name).immortalize(),
6363
collection.name_to_meta.get(name).map(|meta| meta.id),
6464
)
6565
}));
@@ -315,7 +315,7 @@ impl MetadataCollection {
315315
None => {
316316
let order = AttributeId(self.name_to_meta.len());
317317
self.name_to_meta.insert(
318-
Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
318+
YarnBox::new(name).immortalize(),
319319
Metadata {
320320
id: order,
321321
macro_attributes: Default::default(),
@@ -335,10 +335,7 @@ impl MetadataCollection {
335335
Some(meta) => meta.id,
336336
None => {
337337
let order = AttributeId(self.name_to_meta.len());
338-
self.name_to_meta.insert(
339-
Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
340-
order.into(),
341-
);
338+
self.name_to_meta.insert(YarnBox::new(name).immortalize(), order.into());
342339
order
343340
}
344341
}

gix-attributes/src/state.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use bstr::{BStr, ByteSlice};
2-
use byteyarn::{ByteYarn, YarnRef};
2+
use byteyarn::{ByteYarn, YarnBox, YarnRef};
33

44
use crate::{State, StateRef};
55

@@ -49,10 +49,7 @@ impl<'a> From<ValueRef<'a>> for Value {
4949

5050
impl From<&str> for Value {
5151
fn from(v: &str) -> Self {
52-
Value(
53-
ByteYarn::inlined(v.as_bytes())
54-
.unwrap_or_else(|| ByteYarn::from_boxed_bytes(v.as_bytes().to_vec().into_boxed_slice())),
55-
)
52+
Value(YarnBox::new(v).immortalize().into())
5653
}
5754
}
5855

0 commit comments

Comments
 (0)