[llvm] 8f9d3b9 - [StringRef] Use some trickery to avoid initializing the std::string returned by upper()/lower()
Benjamin Kramer via llvm-commits
llvm-commits at lists.llvm.org
Thu May 21 07:03:54 PDT 2020
Author: Benjamin Kramer
Date: 2020-05-21T16:03:09+02:00
New Revision: 8f9d3b937ca7084fcdb9f1b6b4fa93aa1327c628
URL: https://github.com/llvm/llvm-project/commit/8f9d3b937ca7084fcdb9f1b6b4fa93aa1327c628
DIFF: https://github.com/llvm/llvm-project/commit/8f9d3b937ca7084fcdb9f1b6b4fa93aa1327c628.diff
LOG: [StringRef] Use some trickery to avoid initializing the std::string returned by upper()/lower()
Added:
Modified:
llvm/lib/Support/StringRef.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Support/StringRef.cpp b/llvm/lib/Support/StringRef.cpp
index 6ae2a2b532aa..ab67ef9ce85c 100644
--- a/llvm/lib/Support/StringRef.cpp
+++ b/llvm/lib/Support/StringRef.cpp
@@ -106,19 +106,13 @@ unsigned StringRef::edit_distance(llvm::StringRef Other,
//===----------------------------------------------------------------------===//
std::string StringRef::lower() const {
- std::string Result(size(), char());
- for (size_type i = 0, e = size(); i != e; ++i) {
- Result[i] = toLower(Data[i]);
- }
- return Result;
+ return std::string(map_iterator(begin(), toLower),
+ map_iterator(end(), toLower));
}
std::string StringRef::upper() const {
- std::string Result(size(), char());
- for (size_type i = 0, e = size(); i != e; ++i) {
- Result[i] = toUpper(Data[i]);
- }
- return Result;
+ return std::string(map_iterator(begin(), toUpper),
+ map_iterator(end(), toUpper));
}
//===----------------------------------------------------------------------===//
More information about the llvm-commits
mailing list