[cfe-commits] r152321 - in /cfe/trunk: include/clang/AST/Decl.h lib/AST/Decl.cpp
Benjamin Kramer
benny.kra at googlemail.com
Thu Mar 8 11:30:15 PST 2012
On 08.03.2012, at 19:20, Daniel Dunbar wrote:
> Author: ddunbar
> Date: Thu Mar 8 12:20:41 2012
> New Revision: 152321
>
> URL: http://llvm.org/viewvc/llvm-project?rev=152321&view=rev
> Log:
> [AST] Change NamedDecl::getUnderlyingDecl() to inline the fast (and incredibly common) path.
>
> Modified:
> cfe/trunk/include/clang/AST/Decl.h
> cfe/trunk/lib/AST/Decl.cpp
>
> Modified: cfe/trunk/include/clang/AST/Decl.h
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Decl.h?rev=152321&r1=152320&r2=152321&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/AST/Decl.h (original)
> +++ cfe/trunk/include/clang/AST/Decl.h Thu Mar 8 12:20:41 2012
> @@ -323,7 +323,13 @@
>
> /// \brief Looks through UsingDecls and ObjCCompatibleAliasDecls for
> /// the underlying named decl.
> - NamedDecl *getUnderlyingDecl();
> + NamedDecl *getUnderlyingDecl() {
> + if (!(this->getKind() == UsingShadow) &&
> + !(this->getKind() == ObjCCompatibleAlias))
x != y would be a little easier on the eyes than !(x == y)
> + return this;
> + return getUnderlyingDeclImpl();
> + }
> + NamedDecl *getUnderlyingDeclImpl();
The Impl method should be private …
> const NamedDecl *getUnderlyingDecl() const {
> return const_cast<NamedDecl*>(this)->getUnderlyingDecl();
> }
>
> Modified: cfe/trunk/lib/AST/Decl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/Decl.cpp?rev=152321&r1=152320&r2=152321&view=diff
> ==============================================================================
> --- cfe/trunk/lib/AST/Decl.cpp (original)
> +++ cfe/trunk/lib/AST/Decl.cpp Thu Mar 8 12:20:41 2012
> @@ -983,7 +983,7 @@
> return getLinkage() != NoLinkage;
> }
>
> -NamedDecl *NamedDecl::getUnderlyingDecl() {
> +NamedDecl *NamedDecl::getUnderlyingDeclImpl() {
> NamedDecl *ND = this;
> while (true) {
> if (UsingShadowDecl *UD = dyn_cast<UsingShadowDecl>(ND))
… and can assume that ND is a UsingShadowDecl or ObjCCompatibleAliasDecl now, simplifying the code a bit.
- Ben
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
More information about the cfe-commits
mailing list