From 4f9fe856a25ab29345b90e7725509e9ee38a37be Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 17 Apr 2024 14:19:41 +0200 Subject: Adding upstream version 1.69.0+dfsg1. Signed-off-by: Daniel Baumann --- vendor/icu_locid/src/helpers.rs | 46 ++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 24 deletions(-) (limited to 'vendor/icu_locid/src/helpers.rs') diff --git a/vendor/icu_locid/src/helpers.rs b/vendor/icu_locid/src/helpers.rs index e617ded5d..e5889a7b0 100644 --- a/vendor/icu_locid/src/helpers.rs +++ b/vendor/icu_locid/src/helpers.rs @@ -115,7 +115,7 @@ impl ShortVec { #[allow(clippy::unwrap_used)] // we know that the vec has exactly one element left 1 => (ShortVec::Single(v.pop().unwrap()), removed_item), - // v has atleast 2 elements, create a Multi variant + // v has at least 2 elements, create a Multi variant _ => (ShortVec::Multi(v), removed_item), } } @@ -387,6 +387,7 @@ macro_rules! impl_tinystr_subtag { } impl writeable::Writeable for $name { + #[inline] fn write_to(&self, sink: &mut W) -> core::fmt::Result { sink.write_str(self.as_str()) } @@ -394,6 +395,10 @@ macro_rules! impl_tinystr_subtag { fn writeable_length_hint(&self) -> writeable::LengthHint { writeable::LengthHint::exact(self.0.len()) } + #[inline] + fn write_to_string(&self) -> alloc::borrow::Cow { + alloc::borrow::Cow::Borrowed(self.0.as_str()) + } } writeable::impl_display_with_writeable!($name); @@ -546,7 +551,7 @@ macro_rules! impl_tinystr_subtag { } macro_rules! impl_writeable_for_each_subtag_str_no_test { - ($type:tt) => { + ($type:tt $(, $self:ident, $borrow_cond:expr => $borrow:expr)?) => { impl writeable::Writeable for $type { fn write_to(&self, sink: &mut W) -> core::fmt::Result { let mut initial = true; @@ -576,6 +581,20 @@ macro_rules! impl_writeable_for_each_subtag_str_no_test { .expect("infallible"); result } + + $( + fn write_to_string(&self) -> alloc::borrow::Cow { + #[allow(clippy::unwrap_used)] // impl_writeable_for_subtag_list's $borrow uses unwrap + let $self = self; + if $borrow_cond { + $borrow + } else { + let mut output = alloc::string::String::with_capacity(self.writeable_length_hint().capacity()); + let _ = self.write_to(&mut output); + alloc::borrow::Cow::Owned(output) + } + } + )? } writeable::impl_display_with_writeable!($type); @@ -584,7 +603,7 @@ macro_rules! impl_writeable_for_each_subtag_str_no_test { macro_rules! impl_writeable_for_subtag_list { ($type:tt, $sample1:literal, $sample2:literal) => { - impl_writeable_for_each_subtag_str_no_test!($type); + impl_writeable_for_each_subtag_str_no_test!($type, selff, selff.0.len() == 1 => alloc::borrow::Cow::Borrowed(selff.0.as_slice().get(0).unwrap().as_str())); #[test] fn test_writeable() { @@ -593,27 +612,6 @@ macro_rules! impl_writeable_for_subtag_list { &$type::from_vec_unchecked(alloc::vec![$sample1.parse().unwrap()]), $sample1, ); - writeable::assert_writeable_eq!( - &$type::from_vec_unchecked(alloc::vec![ - $sample1.parse().unwrap(), - $sample2.parse().unwrap() - ]), - core::concat!($sample1, "-", $sample2), - ); - } - }; -} - -macro_rules! impl_writeable_for_tinystr_list { - ($type:tt, $if_empty:literal, $sample1:literal, $sample2:literal) => { - impl_writeable_for_each_subtag_str_no_test!($type); - - #[test] - fn test_writeable() { - writeable::assert_writeable_eq!( - &$type::from_vec_unchecked(vec![$sample1.parse().unwrap()]), - $sample1, - ); writeable::assert_writeable_eq!( &$type::from_vec_unchecked(vec![ $sample1.parse().unwrap(), -- cgit v1.2.3