summaryrefslogtreecommitdiff
path: root/chromium/base/strings/strcat.cc
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-12 14:27:29 +0200
committerAllan Sandfeld Jensen <allan.jensen@qt.io>2020-10-13 09:35:20 +0000
commitc30a6232df03e1efbd9f3b226777b07e087a1122 (patch)
treee992f45784689f373bcc38d1b79a239ebe17ee23 /chromium/base/strings/strcat.cc
parent7b5b123ac58f58ffde0f4f6e488bcd09aa4decd3 (diff)
downloadqtwebengine-chromium-85-based.tar.gz
BASELINE: Update Chromium to 85.0.4183.14085-based
Change-Id: Iaa42f4680837c57725b1344f108c0196741f6057 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
Diffstat (limited to 'chromium/base/strings/strcat.cc')
-rw-r--r--chromium/base/strings/strcat.cc62
1 files changed, 11 insertions, 51 deletions
diff --git a/chromium/base/strings/strcat.cc b/chromium/base/strings/strcat.cc
index 35231ef691d..d94c2ea9148 100644
--- a/chromium/base/strings/strcat.cc
+++ b/chromium/base/strings/strcat.cc
@@ -4,82 +4,42 @@
#include "base/strings/strcat.h"
-namespace base {
-
-namespace {
-
-// Reserves an additional amount of capacity in the given string, growing by at
-// least 2x if necessary. Used by StrAppendT().
-//
-// The "at least 2x" growing rule duplicates the exponential growth of
-// std::string. The problem is that most implementations of reserve() will grow
-// exactly to the requested amount instead of exponentially growing like would
-// happen when appending normally. If we didn't do this, an append after the
-// call to StrAppend() would definitely cause a reallocation, and loops with
-// StrAppend() calls would have O(n^2) complexity to execute. Instead, we want
-// StrAppend() to have the same semantics as std::string::append().
-template <typename String>
-void ReserveAdditionalIfNeeded(String* str,
- typename String::size_type additional) {
- const size_t required = str->size() + additional;
- // Check whether we need to reserve additional capacity at all.
- if (required <= str->capacity())
- return;
-
- str->reserve(std::max(required, str->capacity() * 2));
-}
-
-template <typename DestString, typename InputString>
-void StrAppendT(DestString* dest, span<const InputString> pieces) {
- size_t additional_size = 0;
- for (const auto& cur : pieces)
- additional_size += cur.size();
- ReserveAdditionalIfNeeded(dest, additional_size);
+#include <string>
- for (const auto& cur : pieces)
- dest->append(cur.data(), cur.size());
-}
+#include "base/strings/strcat_internal.h"
-} // namespace
+namespace base {
std::string StrCat(span<const StringPiece> pieces) {
- std::string result;
- StrAppendT(&result, pieces);
- return result;
+ return internal::StrCatT(pieces);
}
string16 StrCat(span<const StringPiece16> pieces) {
- string16 result;
- StrAppendT(&result, pieces);
- return result;
+ return internal::StrCatT(pieces);
}
std::string StrCat(span<const std::string> pieces) {
- std::string result;
- StrAppendT(&result, pieces);
- return result;
+ return internal::StrCatT(pieces);
}
string16 StrCat(span<const string16> pieces) {
- string16 result;
- StrAppendT(&result, pieces);
- return result;
+ return internal::StrCatT(pieces);
}
void StrAppend(std::string* dest, span<const StringPiece> pieces) {
- StrAppendT(dest, pieces);
+ internal::StrAppendT(dest, pieces);
}
void StrAppend(string16* dest, span<const StringPiece16> pieces) {
- StrAppendT(dest, pieces);
+ internal::StrAppendT(dest, pieces);
}
void StrAppend(std::string* dest, span<const std::string> pieces) {
- StrAppendT(dest, pieces);
+ internal::StrAppendT(dest, pieces);
}
void StrAppend(string16* dest, span<const string16> pieces) {
- StrAppendT(dest, pieces);
+ internal::StrAppendT(dest, pieces);
}
} // namespace base