diff options
author | Abseil Team <absl-team@google.com> | 2023-06-09 07:46:15 -0700 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-06-09 07:47:12 -0700 |
commit | 87ce390379440febee9caa500e527afa3fa55bef (patch) | |
tree | 33589b0dcb517d961df943e72cac24b17863773a | |
parent | 66eae02ea7c8c41108590de510e70517304d2b6a (diff) | |
download | abseil-87ce390379440febee9caa500e527afa3fa55bef.tar.gz abseil-87ce390379440febee9caa500e527afa3fa55bef.tar.bz2 abseil-87ce390379440febee9caa500e527afa3fa55bef.zip |
The previous code was using `memmove` under the hood (`string::append`).
This patch makes it use `memcpy` for performance and consistency with other overloads.
PiperOrigin-RevId: 539079130
Change-Id: I5aea9dd9b8a1ce708c787df7d6c9a75ae419c484
-rw-r--r-- | absl/strings/str_cat.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/absl/strings/str_cat.cc b/absl/strings/str_cat.cc index 6c198f85..2e49c31b 100644 --- a/absl/strings/str_cat.cc +++ b/absl/strings/str_cat.cc @@ -146,7 +146,13 @@ void AppendPieces(std::string* dest, void StrAppend(std::string* dest, const AlphaNum& a) { ASSERT_NO_OVERLAP(*dest, a); - dest->append(a.data(), a.size()); + std::string::size_type old_size = dest->size(); + strings_internal::STLStringResizeUninitializedAmortized(dest, + old_size + a.size()); + char* const begin = &(*dest)[0]; + char* out = begin + old_size; + out = Append(out, a); + assert(out == begin + dest->size()); } void StrAppend(std::string* dest, const AlphaNum& a, const AlphaNum& b) { |