<br><br><div class="gmail_quote">On Wed, May 2, 2012 at 8:22 PM, Eli Friedman <span dir="ltr"><<a href="mailto:eli.friedman@gmail.com" target="_blank">eli.friedman@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Wed, May 2, 2012 at 7:24 AM, Douglas Gregor <<a href="mailto:dgregor@apple.com">dgregor@apple.com</a>> wrote:<br>
> Author: dgregor<br>
> Date: Wed May  2 09:24:30 2012<br>
> New Revision: 155987<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=155987&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=155987&view=rev</a><br>
> Log:<br>
> Replace the StringSwitch in AttributeList::getKind(const<br>
> IdentifierInfo *) with a static StringMap, improving -fsyntax-only<br>
> performance by 1% for the example in <rdar://problem/11004361>.<br>
><br>
> Modified:<br>
>    cfe/trunk/lib/Sema/AttributeList.cpp<br>
>    cfe/trunk/utils/TableGen/ClangAttrEmitter.cpp<br>
><br>
> Modified: cfe/trunk/lib/Sema/AttributeList.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=155987&r1=155986&r2=155987&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/AttributeList.cpp?rev=155987&r1=155986&r2=155987&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/Sema/AttributeList.cpp (original)<br>
> +++ cfe/trunk/lib/Sema/AttributeList.cpp Wed May  2 09:24:30 2012<br>
> @@ -14,7 +14,7 @@<br>
>  #include "clang/Sema/AttributeList.h"<br>
>  #include "clang/AST/Expr.h"<br>
>  #include "clang/Basic/IdentifierTable.h"<br>
> -#include "llvm/ADT/StringSwitch.h"<br>
> +#include "llvm/ADT/StringMap.h"<br>
>  using namespace clang;<br>
><br>
>  size_t AttributeList::allocated_size() const {<br>
> @@ -97,6 +97,30 @@<br>
>   return create(Name, TokLoc, 0, TokLoc, 0, TokLoc, &IArg, 1, 0);<br>
>  }<br>
><br>
> +<br>
> +typedef llvm::StringMap<AttributeList::Kind> AttributeNameKindMap;<br>
> +<br>
> +static AttributeNameKindMap createAttributeNameKindMap(){<br>
> +  AttributeNameKindMap Result;<br>
> +#include "clang/Sema/AttrParsedAttrKinds.inc"<br>
> +  Result["address_space"] = AttributeList::AT_address_space;<br>
> +  Result["align"] = AttributeList::AT_aligned; // FIXME: should it be "aligned"?<br>
> +  Result["base_check"] = AttributeList::AT_base_check;<br>
> +  Result["bounded"] = AttributeList::IgnoredAttribute; // OpenBSD<br>
> +  Result["__const"] = AttributeList::AT_const; // some GCC headers do contain this spelling<br>
> +  Result["cf_returns_autoreleased"] = AttributeList::AT_cf_returns_autoreleased;<br>
> +  Result["mode"] = AttributeList::AT_mode;<br>
> +  Result["vec_type_hint"] = AttributeList::IgnoredAttribute;<br>
> +  Result["ext_vector_type"] = AttributeList::AT_ext_vector_type;<br>
> +  Result["neon_vector_type"] = AttributeList::AT_neon_vector_type;<br>
> +  Result["neon_polyvector_type"] = AttributeList::AT_neon_polyvector_type;<br>
> +  Result["opencl_image_access"] = AttributeList::AT_opencl_image_access;<br>
> +  Result["objc_gc"] = AttributeList::AT_objc_gc;<br>
> +  Result["objc_ownership"] = AttributeList::AT_objc_ownership;<br>
> +  Result["vector_size"] = AttributeList::AT_vector_size;<br>
> +  return Result;<br>
> +}<br>
> +<br>
>  AttributeList::Kind AttributeList::getKind(const IdentifierInfo *Name) {<br>
>   StringRef AttrName = Name->getName();<br>
><br>
> @@ -105,22 +129,10 @@<br>
>       AttrName.size() >= 4)<br>
>     AttrName = AttrName.substr(2, AttrName.size() - 4);<br>
><br>
> -  return llvm::StringSwitch<AttributeList::Kind>(AttrName)<br>
> -    #include "clang/Sema/AttrParsedAttrKinds.inc"<br>
> -    .Case("address_space", AT_address_space)<br>
> -    .Case("align", AT_aligned) // FIXME - should it be "aligned"?<br>
> -    .Case("base_check", AT_base_check)<br>
> -    .Case("bounded", IgnoredAttribute)       // OpenBSD<br>
> -    .Case("__const", AT_const) // some GCC headers do contain this spelling<br>
> -    .Case("cf_returns_autoreleased", AT_cf_returns_autoreleased)<br>
> -    .Case("mode", AT_mode)<br>
> -    .Case("vec_type_hint", IgnoredAttribute)<br>
> -    .Case("ext_vector_type", AT_ext_vector_type)<br>
> -    .Case("neon_vector_type", AT_neon_vector_type)<br>
> -    .Case("neon_polyvector_type", AT_neon_polyvector_type)<br>
> -    .Case("opencl_image_access", AT_opencl_image_access)<br>
> -    .Case("objc_gc", AT_objc_gc)<br>
> -    .Case("objc_ownership", AT_objc_ownership)<br>
> -    .Case("vector_size", AT_vector_size)<br>
> -    .Default(UnknownAttribute);<br>
> +  static AttributeNameKindMap Map = createAttributeNameKindMap();<br>
<br>
</div></div>IIRC, it isn't safe to use local static variables with MSVC.<br>
<span class="HOEnZb"><font color="#888888"><br>
-Eli<br>
</font></span><div class="HOEnZb"><div class="h5"><br></div></div></blockquote><div>Hi Eli,<br><br>I remember having issues with local static in headers and DLLs (VC++03 managed to put one static per DLL... which is embarassing). It this what you are referring to or is it another issue (thread safety I'd guess) ?<br>
<br>-- Matthieu <br></div></div>