-
Notifications
You must be signed in to change notification settings - Fork 2.7k
#1209 add parseFromString to avoid unnecessary stringstream content copy #1221
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
Conversation
…ingstream content copy
i don't see how this is an optimization. it looks like just adding some new parse variants. I don't really want to make a parse variant for each storage format a user might have, so we have a stream based parse and we have a contiguous char array parse. We don't favor String as source of that buffer. Users are free to write wrappers. |
if I have a string to parse Json from, I should actually do the following (non throwing version):
With the parseFromString being as following
we actually arrive to the following: outside the parseFromStream we wrap a string to a stringstream. Inside parseFromStream we are redirecting it to another stringstream, from which it gets copied to doc object. The latter is then used to get begin and end of the string buffer. |
This isn't what a user with a string should do.
parseFromStream is just capturing a common pattern for a convenient but inefficient dump of an istream. That pattern is inconvenient to formulate from scratch so we wrote it down, but it's not a primary API for Jsoncpp. The reader range parse is really the fundamental kind of parse, and a user with a string can use it readily.
|
If I compare
with I will say length as well as one reference to stringToParse makes difference. And it makes even more sense comparing to now deprecated now deprecated API where it was possible to have So it evolved to dynamic allocation instead of stack, manual memory management (with or without smart pointers) and function call that needs refering the same string 3 times. Wrapping at least memory management and references to string seemed natural. |
BTW, my PR was based on the suggestion to submit it in #1209. |
My only concern would be to avoid binary incompatible changes, and I don't see any of that. This should have a minor version bump though. @BillyDonahue , you've looked at the code pretty closely. You can merge or close this. |
I'm gonna close it. |
Sorry, @fedormsv. I thought it sounded like a good idea. I didn't mean to waste your time. We do appreciate the help. |
Same here. I just think that taking a |
functions for parsing directly from string, without unnecessary pass through string->stringstream->string pipeline