r237475 - Use llvm::StringSwitch<std::string> to take advantage of implicit asserting conversion to std::string.

Peter Collingbourne peter at pcc.me.uk
Fri May 15 15:00:59 PDT 2015


Yes, but this code isn't performance critical, so it doesn't matter.

Peter

On Fri, May 15, 2015 at 02:58:26PM -0700, Craig Topper wrote:
> Doesn't that create a temporary string object for each case? Though maybe
> short string optimization would avoid heap allocation?
> 
> On Fri, May 15, 2015 at 1:11 PM, Peter Collingbourne <peter at pcc.me.uk>
> wrote:
> 
> > Author: pcc
> > Date: Fri May 15 15:11:18 2015
> > New Revision: 237475
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=237475&view=rev
> > Log:
> > Use llvm::StringSwitch<std::string> to take advantage of implicit
> > asserting conversion to std::string.
> >
> > Modified:
> >     cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> >
> > Modified: cfe/trunk/lib/Sema/SemaDeclAttr.cpp
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclAttr.cpp?rev=237475&r1=237474&r2=237475&view=diff
> >
> > ==============================================================================
> > --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp (original)
> > +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp Fri May 15 15:11:18 2015
> > @@ -4381,13 +4381,11 @@ static void handleNoSanitizeAttr(Sema &S
> >  static void handleNoSanitizeSpecificAttr(Sema &S, Decl *D,
> >                                           const AttributeList &Attr) {
> >    std::string SanitizerName =
> > -      llvm::StringSwitch<const char *>(Attr.getName()->getName())
> > +      llvm::StringSwitch<std::string>(Attr.getName()->getName())
> >            .Case("no_address_safety_analysis", "address")
> >            .Case("no_sanitize_address", "address")
> >            .Case("no_sanitize_thread", "thread")
> > -          .Case("no_sanitize_memory", "memory")
> > -          .Default("");
> > -  assert(!SanitizerName.empty());
> > +          .Case("no_sanitize_memory", "memory");
> >    D->addAttr(::new (S.Context)
> >                   NoSanitizeAttr(Attr.getRange(), S.Context,
> > &SanitizerName, 1,
> >                                  Attr.getAttributeSpellingListIndex()));
> >
> >
> > _______________________________________________
> > cfe-commits mailing list
> > cfe-commits at cs.uiuc.edu
> > http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
> >
> 
> 
> 
> -- 
> ~Craig

-- 
Peter



More information about the cfe-commits mailing list