[Lldb-commits] [PATCH] D17274: improve readability and performance of ClangExpressionParser::FindFunctionInModule
Luke Drummond via lldb-commits
lldb-commits at lists.llvm.org
Mon Feb 15 12:09:53 PST 2016
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;
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17274.48003.patch
Type: text/x-patch
Size: 1162 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20160215/64f9a2c7/attachment.bin>
More information about the lldb-commits
mailing list