compact_str icon indicating copy to clipboard operation
compact_str copied to clipboard

Improve efficiency of `is_empty`

Open overlookmotel opened this issue 1 year ago • 10 comments

is_empty checks both inline length and heap length:

https://github.com/ParkMyCar/compact_str/blob/302c595d41373943dc432be2381b8f6a74f0ddf6/compact_str/src/repr/mod.rs#L445-L453

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.

overlookmotel avatar Jan 02 '24 12:01 overlookmotel