Skip to content

Commit

Permalink
Merge branch 'improvements'
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Oct 2, 2023
2 parents 3d60c02 + 7497553 commit 3939a45
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 24 deletions.
11 changes: 4 additions & 7 deletions gix-attributes/src/search/outcome.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bstr::{BString, ByteSlice};
use byteyarn::Yarn;
use byteyarn::YarnBox;
use gix_glob::Pattern;

use crate::{
Expand Down Expand Up @@ -59,7 +59,7 @@ impl Outcome {
self.selected.clear();
self.selected.extend(attribute_names.map(|name| {
(
Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
YarnBox::new(name).immortalize(),
collection.name_to_meta.get(name).map(|meta| meta.id),
)
}));
Expand Down Expand Up @@ -315,7 +315,7 @@ impl MetadataCollection {
None => {
let order = AttributeId(self.name_to_meta.len());
self.name_to_meta.insert(
Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
YarnBox::new(name).immortalize(),
Metadata {
id: order,
macro_attributes: Default::default(),
Expand All @@ -335,10 +335,7 @@ impl MetadataCollection {
Some(meta) => meta.id,
None => {
let order = AttributeId(self.name_to_meta.len());
self.name_to_meta.insert(
Yarn::inlined(name).unwrap_or_else(|| name.to_string().into_boxed_str().into()),
order.into(),
);
self.name_to_meta.insert(YarnBox::new(name).immortalize(), order.into());
order
}
}
Expand Down
7 changes: 2 additions & 5 deletions gix-attributes/src/state.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use bstr::{BStr, ByteSlice};
use byteyarn::{ByteYarn, YarnRef};
use byteyarn::{ByteYarn, YarnBox, YarnRef};

use crate::{State, StateRef};

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

impl From<&str> for Value {
fn from(v: &str) -> Self {
Value(
ByteYarn::inlined(v.as_bytes())
.unwrap_or_else(|| ByteYarn::from_boxed_bytes(v.as_bytes().to_vec().into_boxed_slice())),
)
Value(YarnBox::new(v).immortalize().into())
}
}

Expand Down
4 changes: 3 additions & 1 deletion gix-url/src/parse.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ pub(crate) fn find_scheme(input: &BStr) -> InputScheme {
pub(crate) fn url(input: &BStr, protocol_end: usize) -> Result<crate::Url, Error> {
const MAX_LEN: usize = 1024;
let bytes_to_path = input[protocol_end + "://".len()..]
.find(b"/")
.iter()
.skip_while(|b| **b == b'/')
.position(|b| *b == b'/')
.unwrap_or(input.len() - protocol_end);
if bytes_to_path > MAX_LEN {
return Err(Error::TooLong {
Expand Down
Binary file added gix-url/tests/fixtures/fuzzed/very-long2.url
Binary file not shown.
24 changes: 13 additions & 11 deletions gix-url/tests/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ mod unknown {

#[test]
fn fuzzed() {
let base = Path::new("tests").join("fixtures").join("fuzzed");
let location = base.join(Path::new("very-long").with_extension("url"));
let url = std::fs::read(&location).unwrap();
let start = std::time::Instant::now();
gix_url::parse(url.as_bstr()).ok();
assert!(
start.elapsed() < Duration::from_millis(100),
"URL at '{}' parsed too slowly, took {:.00}s",
location.display(),
start.elapsed().as_secs_f32()
)
for name in ["very-long", "very-long2"] {
let base = Path::new("tests").join("fixtures").join("fuzzed");
let location = base.join(Path::new(name).with_extension("url"));
let url = std::fs::read(&location).unwrap();
let start = std::time::Instant::now();
gix_url::parse(url.as_bstr()).ok();
assert!(
start.elapsed() < Duration::from_millis(100),
"URL at '{}' parsed too slowly, took {:.00}s",
location.display(),
start.elapsed().as_secs_f32()
)
}
}

0 comments on commit 3939a45

Please sign in to comment.