@@ -15,7 +15,8 @@ use std::ptr::{NonNull, null_mut};
1515use std:: { io, thread, time} ;
1616
1717use stdext:: arena:: { Arena , scratch_arena} ;
18- use stdext:: { arena_format, collections} ;
18+ use stdext:: arena_format;
19+ use stdext:: collections:: { BString , BVec } ;
1920
2021use crate :: helpers:: * ;
2122
@@ -182,11 +183,11 @@ pub fn read_stdin(arena: &Arena, mut timeout: time::Duration) -> Option<BString<
182183 // later turn it into UTF8 using `from_utf8_lossy_owned`.
183184 // It is important that we allocate the buffer with an explicit capacity,
184185 // because we later use `spare_capacity_mut` to access it.
185- buf. reserve ( 4 * KIBI ) ;
186+ buf. reserve ( arena , 4 * KIBI ) ;
186187
187188 // We got some leftover broken UTF8 from a previous read? Prepend it.
188189 if STATE . utf8_len != 0 {
189- buf. extend_from_slice ( & STATE . utf8_buf [ ..STATE . utf8_len ] ) ;
190+ buf. extend_from_slice ( arena , & STATE . utf8_buf [ ..STATE . utf8_len ] ) ;
190191 STATE . utf8_len = 0 ;
191192 }
192193
@@ -271,7 +272,7 @@ pub fn read_stdin(arena: &Arena, mut timeout: time::Duration) -> Option<BString<
271272 }
272273 }
273274
274- let mut result = BString :: from_utf8_lossy_owned ( buf) ;
275+ let mut result = BString :: from_utf8_lossy ( arena , buf) ;
275276
276277 // We received a SIGWINCH? Add a fake window size sequence for our input parser.
277278 // I prepend it so that on startup, the TUI system gets first initialized with a size.
@@ -280,12 +281,11 @@ pub fn read_stdin(arena: &Arena, mut timeout: time::Duration) -> Option<BString<
280281 let ( w, h) = get_window_size ( ) ;
281282 if w > 0 && h > 0 {
282283 let scratch = scratch_arena ( Some ( arena) ) ;
283- let seq = arena_format ! ( & scratch, "\x1b [8;{h};{w}t" ) ;
284- result. replace_range ( 0 ..0 , & seq) ;
284+ let seq = arena_format ! ( & * scratch, "\x1b [8;{h};{w}t" ) ;
285+ result. replace_range ( arena , 0 ..0 , & seq) ;
285286 }
286287 }
287288
288- result. shrink_to_fit ( ) ;
289289 Some ( result)
290290 }
291291}
@@ -435,7 +435,7 @@ pub fn icu_detect_renaming_suffix(arena: &Arena, handle: NonNull<c_void>) -> BSt
435435 unsafe {
436436 type T = * const c_void ;
437437
438- let mut res = BString :: new_in ( arena ) ;
438+ let mut res = BString :: empty ( ) ;
439439
440440 // Check if the ICU library is using unversioned symbols.
441441 // Return an empty suffix in that case.
@@ -481,8 +481,8 @@ pub fn icu_detect_renaming_suffix(arena: &Arena, handle: NonNull<c_void>) -> BSt
481481 let version_end = version. find ( '.' ) . unwrap_or ( version. len ( ) ) ;
482482 let version = & version[ ..version_end] ;
483483
484- res. push ( '_' ) ;
485- res. push_str ( version) ;
484+ res. push ( arena , '_' ) ;
485+ res. push_str ( arena , version) ;
486486 res
487487 }
488488}
@@ -506,29 +506,35 @@ where
506506 let name = unsafe { std:: ffi:: CStr :: from_ptr ( name) } ;
507507 let name = unsafe { name. to_str ( ) . unwrap_unchecked ( ) } ;
508508
509- let mut res = ManuallyDrop :: new ( BString :: new_in ( arena ) ) ;
510- res. reserve ( name. len ( ) + suffix. len ( ) + 1 ) ;
511- res. push_str ( name) ;
512- res. push_str ( suffix) ;
513- res. push ( '\0' ) ;
509+ let mut res = BString :: empty ( ) ;
510+ res. reserve ( arena , name. len ( ) + suffix. len ( ) + 1 ) ;
511+ res. push_str ( arena , name) ;
512+ res. push_str ( arena , suffix) ;
513+ res. push ( arena , '\0' ) ;
514514 res. as_ptr ( ) as * const c_char
515515 }
516516}
517517
518- pub fn preferred_languages ( arena : & Arena ) -> Vec < BString < ' _ > , & Arena > {
518+ pub fn preferred_languages ( arena : & Arena ) -> BVec < ' _ , BString < ' _ > > {
519519 let mut locales = BVec :: empty ( ) ;
520520
521521 for key in [ "LANGUAGE" , "LC_ALL" , "LANG" ] {
522522 if let Ok ( val) = std:: env:: var ( key)
523523 && !val. is_empty ( )
524524 {
525- locales. extend ( val. split ( ':' ) . filter ( |s| !s. is_empty ( ) ) . map ( |s| {
526- // Replace all underscores with dashes,
527- // because the localization code expects pt-br, not pt_BR.
528- let mut res = BVec :: empty ( ) ;
529- res. extend ( s. as_bytes ( ) . iter ( ) . map ( |& b| if b == b'_' { b'-' } else { b } ) ) ;
530- unsafe { BString :: from_utf8_unchecked ( res) }
531- } ) ) ;
525+ locales. extend_sloppy (
526+ arena,
527+ val. split ( ':' ) . filter ( |s| !s. is_empty ( ) ) . map ( |s| {
528+ // Replace all underscores with dashes,
529+ // because the localization code expects pt-br, not pt_BR.
530+ let mut res = BVec :: empty ( ) ;
531+ res. extend (
532+ arena,
533+ s. as_bytes ( ) . iter ( ) . map ( |& b| if b == b'_' { b'-' } else { b } ) ,
534+ ) ;
535+ unsafe { BString :: from_utf8_unchecked ( res) }
536+ } ) ,
537+ ) ;
532538 break ;
533539 }
534540 }
0 commit comments