r241088 - Use an early exit to improve readability. (NFC)
David Blaikie
dblaikie at gmail.com
Tue Jun 30 11:09:28 PDT 2015
On Tue, Jun 30, 2015 at 11:01 AM, Adrian Prantl <aprantl at apple.com> wrote:
> Author: adrian
> Date: Tue Jun 30 13:01:05 2015
> New Revision: 241088
>
> URL: http://llvm.org/viewvc/llvm-project?rev=241088&view=rev
> Log:
> Use an early exit to improve readability. (NFC)
>
> Modified:
> cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
>
> Modified: cfe/trunk/lib/CodeGen/CGDebugInfo.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGDebugInfo.cpp?rev=241088&r1=241087&r2=241088&view=diff
>
> ==============================================================================
> --- cfe/trunk/lib/CodeGen/CGDebugInfo.cpp (original)
> +++ cfe/trunk/lib/CodeGen/CGDebugInfo.cpp Tue Jun 30 13:01:05 2015
> @@ -1665,44 +1665,42 @@ llvm::DIType *CGDebugInfo::CreateType(co
>
> llvm::DIModule *
> CGDebugInfo::getOrCreateModuleRef(ExternalASTSource::ASTSourceDescriptor
> Mod) {
> - llvm::DIModule *ModuleRef = nullptr;
> auto it = ModuleRefCache.find(Mod.Signature);
>
Oh, and, assuming this function isn't recursive (ie: the process of
building the DIModule doesn't cause other DIModules to be created/inserted
into ModuleRefCache) you can avoid doing two map lookups:
auto *&ModuleRef = ModuleRefCache[Mod.Signature];
if (ModuleRef)
return ModuleRef
...
ModuleRef = ...;
return ModuleRef;
> if (it != ModuleRefCache.end())
> - ModuleRef = it->second;
> - else {
> - // Macro definitions that were defined with "-D" on the command line.
> - SmallString<128> ConfigMacros;
> - {
> - llvm::raw_svector_ostream OS(ConfigMacros);
> - const auto &PPOpts = CGM.getPreprocessorOpts();
> - unsigned I = 0;
> - // Translate the macro definitions back into a commmand line.
> - for (auto &M : PPOpts.Macros) {
> - if (++I > 1)
> - OS << " ";
> - const std::string &Macro = M.first;
> - bool Undef = M.second;
> - OS << "\"-" << (Undef ? 'U' : 'D');
> - for (char c : Macro)
> - switch (c) {
> - case '\\' : OS << "\\\\"; break;
> - case '"' : OS << "\\\""; break;
> - default: OS << c;
> - }
> - OS << '\"';
> - }
> + return it->second;
> +
> + // Macro definitions that were defined with "-D" on the command line.
> + SmallString<128> ConfigMacros;
> + {
> + llvm::raw_svector_ostream OS(ConfigMacros);
> + const auto &PPOpts = CGM.getPreprocessorOpts();
> + unsigned I = 0;
> + // Translate the macro definitions back into a commmand line.
> + for (auto &M : PPOpts.Macros) {
> + if (++I > 1)
> + OS << " ";
> + const std::string &Macro = M.first;
> + bool Undef = M.second;
> + OS << "\"-" << (Undef ? 'U' : 'D');
> + for (char c : Macro)
> + switch (c) {
> + case '\\' : OS << "\\\\"; break;
> + case '"' : OS << "\\\""; break;
> + default: OS << c;
> + }
> + OS << '\"';
> }
> - llvm::DIBuilder DIB(CGM.getModule());
> - auto *CU = DIB.createCompileUnit(
> - TheCU->getSourceLanguage(), internString(Mod.ModuleName),
> - internString(Mod.Path), TheCU->getProducer(), true, StringRef(),
> 0,
> - internString(Mod.ASTFile), llvm::DIBuilder::FullDebug,
> Mod.Signature);
> - ModuleRef = DIB.createModule(
> - CU, Mod.ModuleName, ConfigMacros, internString(Mod.Path),
> - internString(CGM.getHeaderSearchOpts().Sysroot));
> - DIB.finalize();
> - ModuleRefCache.insert(std::make_pair(Mod.Signature, ModuleRef));
> }
> + llvm::DIBuilder DIB(CGM.getModule());
> + auto *CU = DIB.createCompileUnit(
> + TheCU->getSourceLanguage(), internString(Mod.ModuleName),
> + internString(Mod.Path), TheCU->getProducer(), true, StringRef(), 0,
> + internString(Mod.ASTFile), llvm::DIBuilder::FullDebug,
> Mod.Signature);
> + llvm::DIModule *ModuleRef =
> + DIB.createModule(CU, Mod.ModuleName, ConfigMacros,
> internString(Mod.Path),
> + internString(CGM.getHeaderSearchOpts().Sysroot));
> + DIB.finalize();
> + ModuleRefCache.insert(std::make_pair(Mod.Signature, ModuleRef));
> return ModuleRef;
> }
>
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150630/d136ea35/attachment.html>
More information about the cfe-commits
mailing list