Support get_bytes#4
Conversation
|
@tidwall is there anything else needed for this PR? P.S. Also if you feel it's too much I can make a simpler one only for supporting |
|
Hi Dean, I appreciate the time you spent on the PR. I've only taken a cursory look and from what I can see there's some performance optimizations, which is totally awesome, but unfortunately I currently don't the time needed to do a thorough review. Hopefully in the near future. I'm not sure about the logistics of your current work, but in the meantime could there be a way to maintain a forked crate? |
|
Yes I could look at a forked crate for now. Unfortunate that there will be multiple published gjson crates, but not the end of the world. Thanks for letting me know. |
The main goal of this PR was to add a new function
gjson::get_bytes(...)to compliment thegjson::get(...)preventing the need to convert to a string, but noticed a few other things while doing that so the highlights are:gjson::get_bytes(...)to compliment thegjson::get(...)hereValueby usingCowcombining thesliceandownedfields into one and deferring escaping strings until needed/used, see here&strand then immediately calledas_bytes()on that string to accept a&[u8]directly which has reduced the need to convert between these types as well as returningVec<u8>instead ofStringto help facilitate. See here for example.!data.is_empty()vsdata.len() > 0for readability.These changes, for a project I'm using gjson in, benchmarked 5-10% faster in some situations when fetching values.