8000 Support get_bytes by deankarn · Pull Request #4 · tidwall/gjson.rs · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Support get_bytes #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Support get_bytes #4

wants to merge 6 commits into from

Conversation

deankarn
Copy link
@deankarn deankarn commented Mar 20, 2022

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
Copy link
Author
deankarn commented Mar 29, 2022

@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 :)

@tidwall
Copy link
Owner
tidwall commented Mar 30, 2022

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?

@deankarn
Copy link
Author

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.

@deankarn deankarn mentioned this pull request Apr 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0