[lld] r228069 - Avoid two function calls of file() when not needed.

Rui Ueyama ruiu at google.com
Tue Feb 3 16:20:33 PST 2015


The coding standard doesn't cover that kind of thing. It doesn't ban me
from writing extremely long functions or name variables in Spanish or
whatnot. It's just that which is better and readable code.

On Tue, Feb 3, 2015 at 4:10 PM, Davide Italiano <davide at freebsd.org> wrote:

> On Tue, Feb 3, 2015 at 4:01 PM, Rui Ueyama <ruiu at google.com> wrote:
> > On Tue, Feb 3, 2015 at 3:44 PM, Davide Italiano <davide at freebsd.org>
> wrote:
> >>
> >> Author: davide
> >> Date: Tue Feb  3 17:44:33 2015
> >> New Revision: 228069
> >>
> >> URL: http://llvm.org/viewvc/llvm-project?rev=228069&view=rev
> >> Log:
> >> Avoid two function calls of file() when not needed.
> >>
> >> Reported by:    ruiu
> >>
> >> Modified:
> >>     lld/trunk/lib/Core/DefinedAtom.cpp
> >>
> >> Modified: lld/trunk/lib/Core/DefinedAtom.cpp
> >> URL:
> >>
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/DefinedAtom.cpp?rev=228069&r1=228068&r2=228069&view=diff
> >>
> >>
> ==============================================================================
> >> --- lld/trunk/lib/Core/DefinedAtom.cpp (original)
> >> +++ lld/trunk/lib/Core/DefinedAtom.cpp Tue Feb  3 17:44:33 2015
> >> @@ -83,12 +83,15 @@ DefinedAtom::ContentPermissions DefinedA
> >>
> >>  bool DefinedAtom::compareByPosition(const DefinedAtom *lhs,
> >>                                      const DefinedAtom *rhs) {
> >> -  const File *lhsFile = &lhs->file();
> >> -  const File *rhsFile = &rhs->file();
> >> +  const File *lhsFile;
> >> +  const File *rhsFile;
> >>
> >>    if (lhs == rhs)
> >>      return false;
> >>
> >> +  lhsFile = &lhs->file();
> >> +  rhsFile = &rhs->file();
> >> +
> >>    if (lhsFile->ordinal() != rhsFile->ordinal())
> >>      return lhsFile->ordinal() < rhsFile->ordinal();
> >>    assert(lhs->ordinal() != rhs->ordinal());
> >
> >
> > Oh, the new code looks like too C89-ish. You could have intermingled
> > declarations and code like this. It's better to do pre-commit code
> review,
> > perhaps?
> >
>
> FWIW, I haven't seen anything against that in
> http://llvm.org/docs/CodingStandards.html , unless I overlooked (which
> might be possible).
> I can change that again if you really want.
>
> --
> Davide
>
> "There are no solved problems; there are only problems that are more
> or less solved" -- Henri Poincare
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20150203/70699622/attachment.html>


More information about the llvm-commits mailing list