diff options
author | Abseil Team <absl-team@google.com> | 2023-01-19 00:47:09 -0800 |
---|---|---|
committer | Copybara-Service <copybara-worker@google.com> | 2023-01-19 00:48:08 -0800 |
commit | 25a85cdd6f55453574f9535ff1be983a1abef841 (patch) | |
tree | e98772a2391b2b4deb11879fee7f9f9707135080 /absl | |
parent | 857325a937efa2996c691d6bdcdec8605472e638 (diff) |
Use absl::string_view by value rather than by const reference while iterating over collections.
PiperOrigin-RevId: 503088193
Change-Id: Ic1f239f3b0427e0fea1643ec0ce7baff45ad647d
Diffstat (limited to 'absl')
-rw-r--r-- | absl/strings/str_cat.cc | 8 | ||||
-rw-r--r-- | absl/strings/str_split_test.cc | 2 |
2 files changed, 5 insertions, 5 deletions
diff --git a/absl/strings/str_cat.cc b/absl/strings/str_cat.cc index e5cb6d84..114a2ff2 100644 --- a/absl/strings/str_cat.cc +++ b/absl/strings/str_cat.cc @@ -144,12 +144,12 @@ namespace strings_internal { std::string CatPieces(std::initializer_list<absl::string_view> pieces) { std::string result; size_t total_size = 0; - for (const absl::string_view& piece : pieces) total_size += piece.size(); + for (absl::string_view piece : pieces) total_size += piece.size(); strings_internal::STLStringResizeUninitialized(&result, total_size); char* const begin = &result[0]; char* out = begin; - for (const absl::string_view& piece : pieces) { + for (absl::string_view piece : pieces) { const size_t this_size = piece.size(); if (this_size != 0) { memcpy(out, piece.data(), this_size); @@ -173,7 +173,7 @@ void AppendPieces(std::string* dest, std::initializer_list<absl::string_view> pieces) { size_t old_size = dest->size(); size_t total_size = old_size; - for (const absl::string_view& piece : pieces) { + for (absl::string_view piece : pieces) { ASSERT_NO_OVERLAP(*dest, piece); total_size += piece.size(); } @@ -181,7 +181,7 @@ void AppendPieces(std::string* dest, char* const begin = &(*dest)[0]; char* out = begin + old_size; - for (const absl::string_view& piece : pieces) { + for (absl::string_view piece : pieces) { const size_t this_size = piece.size(); if (this_size != 0) { memcpy(out, piece.data(), this_size); diff --git a/absl/strings/str_split_test.cc b/absl/strings/str_split_test.cc index 1b4427b8..04a64a42 100644 --- a/absl/strings/str_split_test.cc +++ b/absl/strings/str_split_test.cc @@ -369,7 +369,7 @@ TEST(SplitIterator, EqualityAsEndCondition) { TEST(Splitter, RangeIterators) { auto splitter = absl::StrSplit("a,b,c", ','); std::vector<absl::string_view> output; - for (const absl::string_view& p : splitter) { + for (absl::string_view p : splitter) { output.push_back(p); } EXPECT_THAT(output, ElementsAre("a", "b", "c")); |