Remove HeaderString::c_str() and migrate callers to getStringView()#6564
Remove HeaderString::c_str() and migrate callers to getStringView()#6564lizan merged 10 commits intoenvoyproxy:masterfrom
Conversation
Signed-off-by: Dan Noé <dpn@google.com>
Signed-off-by: Dan Noé <dpn@google.com>
This doesn't work, of course. Signed-off-by: Dan Noé <dpn@google.com>
|
The old code in the section that failed to build in release and coverage builds is this: I'll admit to being a little confused about what it means to assign a It's also unclear why the other configurations didn't fail to build. |
|
@dnoe Yeah it'll create a temporary and its lifetime is extended (https://abseil.io/tips/107) |
Signed-off-by: Dan Noé <dpn@google.com>
Now that we use string_view, we can use range-based-for and make the loop more readable. Signed-off-by: Dan Noé <dpn@google.com>
|
Looks great! |
lizan
left a comment
There was a problem hiding this comment.
Great, I only reviewed until source/common though.
source/common/grpc/common.cc
Outdated
| grpc_status->value().getStringView())) | ||
| .inc(); | ||
| uint64_t grpc_status_code; | ||
| std::string grpc_status_string(grpc_status->value().getStringView()); |
There was a problem hiding this comment.
consider use absl::SimpleAtoi instead of atoull (or implement StringUtil::atoull with absl::SimpleAtoi) so we can avoid this string allocation.
There was a problem hiding this comment.
Great idea - I will create an issue to follow up by either implementing StringUtil::atoull with absl::SimpleAtoi or converting call sites. I think there was only one spot in the code I found where the return value of StringUtil::atoull (which is C-style) was used.
mattklein123
left a comment
There was a problem hiding this comment.
Thanks this is absolutely awesome. Huge props for slogging through this and I love seeing the tech debt disappear.
I mainly have comments around adding TODOs for all the other places we can get rid of string copies. We have the opportunity here to speed things up in a non-trivial way as part of these changes which is great.
/wait
source/common/grpc/common.cc
Outdated
| grpc_status->value().getStringView())) | ||
| .inc(); | ||
| uint64_t grpc_status_code; | ||
| std::string grpc_status_string(grpc_status->value().getStringView()); |
There was a problem hiding this comment.
nit: const here and elsewhere.
There was a problem hiding this comment.
Done, though my eyes glaze over reading this diff so please let me know if I missed another :)
source/common/http/header_utility.cc
Outdated
| } | ||
|
|
||
| bool match; | ||
| absl::string_view header_view = header->value().getStringView(); |
There was a problem hiding this comment.
Do we have to make this copy? If so can we TODO removing it?
There was a problem hiding this comment.
This one is just for readability reasons since it gets pretty busy seeing header->value().getStringView() repeated especially when std::regex_match takes begin() and end(). The copy of a string_view should be only slightly worse than a pointer. I've marked it as const, which may prevent the copy entirely.
I'm happy to remove it too if you'd like, but I think it makes this much more readable rather than repeating the header->value().getStringView().
| @@ -66,7 +66,7 @@ Decision HttpTracerUtility::isTracing(const StreamInfo::StreamInfo& stream_info, | |||
|
|
|||
| // TODO PERF: Avoid copy. | |||
There was a problem hiding this comment.
Indeed I did now that isTraceableUuid takes string_view rather than std::string. Removing the comment, taking the credit (I don't see an existing issue for this, if there is feel free to close it).
Signed-off-by: Dan Noé <dpn@google.com>
mattklein123
left a comment
There was a problem hiding this comment.
Nice this is so awesome. Looking forward to the followup cleanups. A few more comments from another pass. Thank you!
/wait
Use lua_pushlstring to avoid std::string construction. Signed-off-by: Dan Noé <dpn@google.com>
mattklein123
left a comment
There was a problem hiding this comment.
Nice! @lizan do you want to do any additional review?
Signed-off-by: Dan Noé <dpn@google.com>
…c_str_by_the_c_shore
…c_str_by_the_c_shore Signed-off-by: Dan Noe <dpn@google.com>
|
Master merge conflicts addressed. |
Remove the
HeaderString::c_str()API, and migrate all callers of it togetStringView()andstring_viewstyle usage (ie,absl::string_view::findinstead of C style comparisons) wherever appropriate.Risk Level: Medium. No logic changes intended, but this is delicate and risky code and a large portion of the code base was touched.
Testing:
bazel test //test/...Docs Changes: None
Release Notes: None
Fixes #6494