-
Notifications
You must be signed in to change notification settings - Fork 53
Open
Description
is_empty checks both inline length and heap length:
compact_str/compact_str/src/repr/mod.rs
Lines 445 to 453 in 302c595
| pub fn is_empty(&self) -> bool { | |
| let len_heap = ensure_read(self.1); | |
| let last_byte = self.last_byte() as usize; | |
| let mut len = last_byte.wrapping_sub(LastUtf8Char::L0 as u8 as usize); | |
| if last_byte >= LastUtf8Char::Heap as u8 as usize { | |
| len = len_heap; | |
| } | |
| len == 0 | |
| } |
I believe an empty string is always stored inline. Therefore it could be reduced to:
pub fn is_empty(&self) -> bool {
self.last_byte() == LastUtf8Char::L0 as u8
}If my assumption is correct, let me know and I'll make a PR.
Metadata
Metadata
Assignees
Labels
No labels