Conversation
|
Great cleanup, thanks!
Ah yeah. I think this code was written prior to error-boxing, and I must have missed it in code review. This allocation should probably be avoided as I'm pretty sure the compiler isn't smart enough to remove. If you want to take this on in your PR, I'd put error creation into a closure, and call it when an error occurs. If not, I'll address it in a follow-up PR.
I'm pretty sure that I benchmarked this earlier and found that the lookup table was faster. That might have been specific to the architecture that I was on though? It looks like most CPUs have a pretty fast |
let error = || {
ErrorKind::InvalidEncoding{
desc: "Invalid char encoding",
detail: None
}.into()
};
...
if width == 0 { return Err(error())}Like this?
I must admit I had no performance benefits in mind. I guess the bit twiddling + match might be slower than the lookup table. |
Yep!
Yeah. I'll file an issue to do more benchmarking at a later date. |
|
👍 |
This PR does the following things in
deserialize_char:unwrap()that was probably impossible to panicsince
str::from_utf8checks the encoding, but anyway.read_exactbecause the while loop may notreturn on malformed input:
Things I didn't change:
to move it into the right places. It is boxed, so this means one heap allocation/deallocation
on every call to
deserialize_char?UTF8_CHAR_WIDTHtable and theutf8_char_widthfunction could be replaced with something like