File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11use bstr:: { BString , ByteSlice } ;
2- use byteyarn:: Yarn ;
2+ use byteyarn:: YarnBox ;
33use gix_glob:: Pattern ;
44
55use 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 }
Original file line number Diff line number Diff line change 11use bstr:: { BStr , ByteSlice } ;
2- use byteyarn:: { ByteYarn , YarnRef } ;
2+ use byteyarn:: { ByteYarn , YarnBox , YarnRef } ;
33
44use crate :: { State , StateRef } ;
55
@@ -49,10 +49,7 @@ impl<'a> From<ValueRef<'a>> for Value {
4949
5050impl 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
Original file line number Diff line number Diff line change @@ -85,7 +85,9 @@ pub(crate) fn find_scheme(input: &BStr) -> InputScheme {
8585pub ( 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 {
Original file line number Diff line number Diff line change @@ -139,15 +139,17 @@ mod unknown {
139139
140140#[ test]
141141fn 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}
You can’t perform that action at this time.
0 commit comments