mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-12-23 08:48:08 +00:00
Add test from_buf_and_chars_size_hinted_heap & fix
This commit is contained in:
parent
c9cd0324a7
commit
b4ce6529fa
1 changed files with 16 additions and 1 deletions
|
|
@ -245,7 +245,11 @@ fn from_buf_and_chars(
|
|||
) -> SmolStr {
|
||||
let min_size = iter.size_hint().0 + buf_len;
|
||||
if min_size > INLINE_CAP {
|
||||
let heap: String = iter.collect();
|
||||
let heap: String = core::str::from_utf8(&buf[..buf_len])
|
||||
.unwrap()
|
||||
.chars()
|
||||
.chain(iter)
|
||||
.collect();
|
||||
if heap.len() <= INLINE_CAP {
|
||||
// size hint lied
|
||||
return SmolStr::new_inline(&heap);
|
||||
|
|
@ -940,3 +944,14 @@ impl<'a> arbitrary::Arbitrary<'a> for SmolStr {
|
|||
mod borsh;
|
||||
#[cfg(feature = "serde")]
|
||||
mod serde;
|
||||
|
||||
#[test]
|
||||
fn from_buf_and_chars_size_hinted_heap() {
|
||||
let str = from_buf_and_chars(
|
||||
*b"abcdefghijklmnopqr00000",
|
||||
18,
|
||||
"_0x1x2x3x4x5x6x7x8x9x10x11x12x13".chars(),
|
||||
);
|
||||
|
||||
assert_eq!(str, "abcdefghijklmnopqr_0x1x2x3x4x5x6x7x8x9x10x11x12x13");
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue