Open deankarn opened 2 years ago
@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 get_bytes
in the meantime if that helps as I need it to deploy my crate :)
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(...)
hereValue
by usingCow
combining theslice
andowned
fields into one and deferring escaping strings until needed/used, see here&str
and 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 ofString
to help facilitate. See here for example.!data.is_empty()
vsdata.len() > 0
for readability.These changes, for a project I'm using gjson in, benchmarked 5-10% faster in some situations when fetching values.