mirror of
https://github.com/openharmony/third_party_rust_tinyvec.git
synced 2026-07-18 12:25:35 -04:00
Improve Write impl efficiency
This commit is contained in:
+6
-8
@@ -1031,16 +1031,14 @@ where
|
||||
A::Item: From<u8>,
|
||||
{
|
||||
fn write_str(&mut self, s: &str) -> core::fmt::Result {
|
||||
if self.len() + s.as_bytes().len() > A::CAPACITY {
|
||||
return Err(core::fmt::Error)
|
||||
}
|
||||
let mut buf = [0; 4];
|
||||
for c in s.chars() {
|
||||
for b in c.encode_utf8(&mut buf) {
|
||||
self.push(*b);
|
||||
if self.len() + s.as_bytes().len() <= A::CAPACITY {
|
||||
for byte in s.bytes() {
|
||||
self.push(A::Item::from(byte))
|
||||
}
|
||||
Ok(())
|
||||
} else {
|
||||
Err(core::fmt::Error)
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user