Skip to content

Commit 3939a45

Browse files
committed
Merge branch 'improvements'
2 parents 3d60c02 + 7497553 commit 3939a45

File tree

5 files changed

+22
-24
lines changed

5 files changed

+22
-24
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

gix-url/src/parse.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ pub(crate) fn find_scheme(input: &BStr) -> InputScheme {
8585
pub(crate) fn url(input: &BStr, protocol_end: usize) -> Result<crate::Url, Error> {
8686
const MAX_LEN: usize = 1024;
8787
let bytes_to_path = input[protocol_end + "://".len()..]
88-
.find(b"/")
88+
.iter()
89+
.skip_while(|b| **b == b'/')
90+
.position(|b| *b == b'/')
8991
.unwrap_or(input.len() - protocol_end);
9092
if bytes_to_path > MAX_LEN {
9193
return Err(Error::TooLong {
146 KB
Binary file not shown.

gix-url/tests/parse/mod.rs

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,17 @@ mod unknown {
139139

140140
#[test]
141141
fn fuzzed() {
142-
let base = Path::new("tests").join("fixtures").join("fuzzed");
143-
let location = base.join(Path::new("very-long").with_extension("url"));
144-
let url = std::fs::read(&location).unwrap();
145-
let start = std::time::Instant::now();
146-
gix_url::parse(url.as_bstr()).ok();
147-
assert!(
148-
start.elapsed() < Duration::from_millis(100),
149-
"URL at '{}' parsed too slowly, took {:.00}s",
150-
location.display(),
151-
start.elapsed().as_secs_f32()
152-
)
142+
for name in ["very-long", "very-long2"] {
143+
let base = Path::new("tests").join("fixtures").join("fuzzed");
144+
let location = base.join(Path::new(name).with_extension("url"));
145+
let url = std::fs::read(&location).unwrap();
146+
let start = std::time::Instant::now();
147+
gix_url::parse(url.as_bstr()).ok();
148+
assert!(
149+
start.elapsed() < Duration::from_millis(100),
150+
"URL at '{}' parsed too slowly, took {:.00}s",
151+
location.display(),
152+
start.elapsed().as_secs_f32()
153+
)
154+
}
153155
}

0 commit comments

Comments
 (0)