File tree Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Expand file tree Collapse file tree 1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change @@ -245,7 +245,11 @@ fn from_buf_and_chars(
245245) -> SmolStr {
246246 let min_size = iter. size_hint ( ) . 0 + buf_len;
247247 if min_size > INLINE_CAP {
248- let heap: String = iter. collect ( ) ;
248+ let heap: String = core:: str:: from_utf8 ( & buf[ ..buf_len] )
249+ . unwrap ( )
250+ . chars ( )
251+ . chain ( iter)
252+ . collect ( ) ;
249253 if heap. len ( ) <= INLINE_CAP {
250254 // size hint lied
251255 return SmolStr :: new_inline ( & heap) ;
@@ -940,3 +944,14 @@ impl<'a> arbitrary::Arbitrary<'a> for SmolStr {
940944mod borsh;
941945#[ cfg( feature = "serde" ) ]
942946mod serde;
947+
948+ #[ test]
949+ fn from_buf_and_chars_size_hinted_heap ( ) {
950+ let str = from_buf_and_chars (
951+ * b"abcdefghijklmnopqr00000" ,
952+ 18 ,
953+ "_0x1x2x3x4x5x6x7x8x9x10x11x12x13" . chars ( ) ,
954+ ) ;
955+
956+ assert_eq ! ( str , "abcdefghijklmnopqr_0x1x2x3x4x5x6x7x8x9x10x11x12x13" ) ;
957+ }
You can’t perform that action at this time.
0 commit comments