gjson.rs icon indicating copy to clipboard operation
gjson.rs copied to clipboard

Support get_bytes

Open deankarn opened this issue 2 years ago • 3 comments

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 the gjson::get(...) here
  • Simplified and reduced size of Value by using Cow combining the slice and owned fields into one and deferring escaping strings until needed/used, see here
  • Converted a bunch of functions that accepted a &str and then immediately called as_bytes() on that string to accept a &[u8] directly which has reduced the need to convert between these types as well as returning Vec<u8> instead of String to help facilitate. See here for example.
  • Cleaned up some checks to be more idiomatic rust eg. !data.is_empty() vs data.len() > 0 for readability.

These changes, for a project I'm using gjson in, benchmarked 5-10% faster in some situations when fetching values.

deankarn avatar Mar 20 '22 17:03 deankarn