gjson.rs
gjson.rs copied to clipboard
Support get_bytes
The main goal of this PR was to add a new function gjson::get_bytes(...)
to compliment the gjson::get(...)
preventing the need to convert to a string, but noticed a few other things while doing that so the highlights are:
- Added
gjson::get_bytes(...)
to compliment thegjson::get(...)
here - Simplified and reduced size of
Value
by usingCow
combining theslice
andowned
fields into one and deferring escaping strings until needed/used, see here - Converted a bunch of functions that accepted a
&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. - Cleaned up some checks to be more idiomatic rust eg.
!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.