-
Notifications
You must be signed in to change notification settings - Fork 617
allow to parse const char * without mem allocation #60
base: master
Are you sure you want to change the base?
Conversation
Automated message from Dropbox CLA bot @Dushistov, it looks like you've already signed the Dropbox CLA. Thanks! |
I have already signed the copyright assignment, when creating other pull requests. |
I'm not really comfortable implementing a part of |
it is inside json11 namespace and all methods of it are inline, so it not cause compile time errors,
I thought about it, but if you use So you will have string_view with different name, and guy who look at code after you will say "Hey, they just re-implemented string_view, why?`, so why hide truth and not explicity implement string_view and add note about it? One more possible solution may be
So you can replace string_view implementation to your own internal, or just What do you think? |
You might be able to minimize the internal impact without forcing the class itself to be a template, if you have a template method which takes something string-view-like. E.g. implement your own internal string-view-like thing (simpler than the real string view since you only need a subset of functionality), then have a method like this:
That should work for any input type which supports data() and length(), including std::string and std::experimental::string_view. For full flexibility I'd suggest also providing a ptr+length form of the method:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Invoking the new code-review process for this. Comment/requests are in the previous discussion above.
At now, if you have
json
data instd::vector<char>
,QByteArray
(fromQt
) orconst char *
, then to parsejson
withjson11
you need to do unnecessary memory allocation to convert (pointer, size) pair tostd::string. This patch replace std::string interface for parsing with simple structure string_view = pair of pointer and size.
native json benchmark (https://github.com/miloyip/nativejson-benchmark) show:
without this patch
Parse Time (ms)
-51
with this patch
Parse Time (ms)
-8,837
benchmark uses
parse(const char * in,...)
interface.string_view (pair of pointer and size) implement part of interface of std::basic_string_view(http://en.cppreference.com/w/cpp/string/basic_string_view).