-
Notifications
You must be signed in to change notification settings - Fork 584
Make JsonEncode() a bit faster #10400
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
base: master
Are you sure you want to change the base?
Conversation
so that e.g. `String("foo")+"bar"` re-uses `String("foo")` instead of copying.
Please add proof. |
Could you please give this PR an actual useful title that does not bow to the alt-right? |
String icinga::operator+(String&& lhs, const char *rhs) | ||
{ | ||
return std::move(lhs.GetData()) + rhs; | ||
} | ||
|
||
String icinga::operator+(const char *lhs, const String& rhs) | ||
{ | ||
return lhs + rhs.GetData(); | ||
} | ||
|
||
String icinga::operator+(const char *lhs, String&& rhs) | ||
{ | ||
return lhs + std::move(rhs.GetData()); | ||
} |
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.
How did you get here? Like how did you get to the conclusion that this will be a useful optimization?
(Also, I really wonder if there's actually an implementation of std::string
that allows prepending without reallocation (unless you prepend the empty string), but well, a corresponding overload of operator+
is provided for std::string
.)
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.
How did you get here? Like how did you get to the conclusion that this will be a useful optimization?
Checkout 27e1850 and Cmd+LClick the + sign in
Line 199 in 27e1850
return stateMachine.GetResult() + "\n"; |
CLion will open String icinga::operator+(const String&,const char*)
which copies the string.
(Also, I really wonder if there's actually an implementation of
std::string
that allows prepending without reallocation
As long as there's enough free capacity, there's no reason to reallocate.
a corresponding overload of
operator+
is provided forstd::string
.)
Exactly.
ebf042a
to
0e647d0
Compare
@julianbrost As discussed offline, I had a look at JsonEncode() which appeared while profiling
ref/NC/820479
to make it faster.