| Code-Review | +1 |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
Create a string_view instead of string from char*.
This avoids an unnecessary string copy.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
const std::string name = std::string(raw.substr(start_pos, len));Nice change! Just saw it flying by, and was wondering why this still creates a `std::string` copy instead of using `string_view` as well?
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
const std::string name = std::string(raw.substr(start_pos, len));Nice change! Just saw it flying by, and was wondering why this still creates a `std::string` copy instead of using `string_view` as well?
I wasn't sure whether it was safe to use a string_view to replace the second copy for use with snprintf. string_view doesn't have a `.c_str()` method, and `.data()` on string_view doesn't terminate with the null character.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |
const std::string name = std::string(raw.substr(start_pos, len));Jeffrey YuNice change! Just saw it flying by, and was wondering why this still creates a `std::string` copy instead of using `string_view` as well?
I wasn't sure whether it was safe to use a string_view to replace the second copy for use with snprintf. string_view doesn't have a `.c_str()` method, and `.data()` on string_view doesn't terminate with the null character.
It looks like the whole point of the `snprintf` is to add the terminating null character. So you can replace it with a `memcpy` plus setting the last character to `'\0'` explicitly. That skips the intermediate copy via `std::string`.
| Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. |