diff options
author | Chris Lattner <sabre@nondot.org> | 2008-11-20 04:42:34 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-11-20 04:42:34 +0000 |
commit | 92e62b02226410bcad8584541b8f1ff4d35ebab9 (patch) | |
tree | aff14a293c5b7307ead4c35ae21ff1c6e940196e /include/clang/Basic/IdentifierTable.h | |
parent | a751217e769cbe73df2d579a28153f1c947aef10 (diff) |
Rename IdentifierInfo::isName to ::isStr. Use a nifty trick
from Sebastian to enforce that a literal string is passed in,
and use this to avoid having to call strlen on it.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59706 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/IdentifierTable.h')
-rw-r--r-- | include/clang/Basic/IdentifierTable.h | 9 |
1 files changed, 5 insertions, 4 deletions
diff --git a/include/clang/Basic/IdentifierTable.h b/include/clang/Basic/IdentifierTable.h index 7801304751..348ef1477f 100644 --- a/include/clang/Basic/IdentifierTable.h +++ b/include/clang/Basic/IdentifierTable.h @@ -62,10 +62,11 @@ class IdentifierInfo { public: IdentifierInfo(); - /// isName - Return true if this is the identifier for the specified string. - bool isName(const char *Str) const { - unsigned Len = strlen(Str); - return getLength() == Len && !memcmp(getName(), Str, Len); + /// isStr - Return true if this is the identifier for the specified string. + /// This is intended to be used for string literals only: II->isStr("foo"). + template <std::size_t StrLen> + bool isStr(const char (&Str)[StrLen]) const { + return getLength() == StrLen-1 && !memcmp(getName(), Str, StrLen-1); } /// getName - Return the actual string for this identifier. The returned |