ldrumm created this revision.
ldrumm added reviewers: spyffe, dawn.
ldrumm added a subscriber: lldb-commits.

- Prefer `llvm::StringRef::find` over allocating a `std::string` and then 
discarding it after calling the equivalent `find` method.
- improve readability of function iterator, and make the function variable a 
`const` ref.
- Prefer passing `StringRef` directly to `ConstString::setString(StringRef &)` 
over allocating a new `std::string` from a StringRef only to convert to `const 
char *`, which is then passed to  ConstString::setCString(const char *)


http://reviews.llvm.org/D17274

Files:
  source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp

Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -556,17 +556,15 @@
     return num_errors;
 }
 
-static bool FindFunctionInModule (ConstString &mangled_name,
-                                  llvm::Module *module,
-                                  const char *orig_name)
+static bool
+FindFunctionInModule(ConstString &mangled_name, llvm::Module *module, const 
char *orig_name)
 {
-    for (llvm::Module::iterator fi = module->getFunctionList().begin(), fe = 
module->getFunctionList().end();
-         fi != fe;
-         ++fi)
+    for (const auto &func : module->getFunctionList())
     {
-        if (fi->getName().str().find(orig_name) != std::string::npos)
+        const StringRef &name = func.getName();
+        if (name.find(orig_name) != StringRef::npos)
         {
-            mangled_name.SetCString(fi->getName().str().c_str());
+            mangled_name.SetString(name);
             return true;
         }
     }


Index: source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
===================================================================
--- source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
+++ source/Plugins/ExpressionParser/Clang/ClangExpressionParser.cpp
@@ -556,17 +556,15 @@
     return num_errors;
 }
 
-static bool FindFunctionInModule (ConstString &mangled_name,
-                                  llvm::Module *module,
-                                  const char *orig_name)
+static bool
+FindFunctionInModule(ConstString &mangled_name, llvm::Module *module, const char *orig_name)
 {
-    for (llvm::Module::iterator fi = module->getFunctionList().begin(), fe = module->getFunctionList().end();
-         fi != fe;
-         ++fi)
+    for (const auto &func : module->getFunctionList())
     {
-        if (fi->getName().str().find(orig_name) != std::string::npos)
+        const StringRef &name = func.getName();
+        if (name.find(orig_name) != StringRef::npos)
         {
-            mangled_name.SetCString(fi->getName().str().c_str());
+            mangled_name.SetString(name);
             return true;
         }
     }
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to