r200889 - Fix -Wunused-variable 'FD' by using it instead of ND when they're equal but FD

Chandler Carruth chandlerc at google.com
Wed Feb 5 21:19:46 PST 2014


On Wed, Feb 5, 2014 at 9:04 PM, Nick Lewycky <nicholas at mxc.ca> wrote:

> Is this better than using isa<>  instead of dyn_cast<>  in some way? Ie,
>>
>>      } else if (isa<FunctionDecl>(ND)) {
>>        const CXXMethodDecl *MD = dyn_cast<CXXMethodDecl>(ND);
>>        ...
>>
>
> I haven't bothered to check, but probably not. The isa<> method calls
> classof, but you can overload classof at any level. If CXXMethodDecl has
> different classof implementations for when the static type is a
> FunctionDecl vs. NamedDecl, then it could be better.
>
> But I didn't really think about it. It's common to declare the variable
> and then use it, and I figured that it was probably intended that way. I
> don't much care, if you want to change it, or if you want me to change it.
> Whatever.


Well, there is a concrete difference: the table of the switch for casting
from FunctionDecl to CXXMethodDecl is smaller than the table for NamedDecl
to CXXMethodDecl. In that sense, it is a (minute) performance improvement
to use the most-refined type statically available.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140205/18012d07/attachment.html>


More information about the cfe-commits mailing list