[lld] r205576 - Replace a recursion with a loop for speed.

David Blaikie dblaikie at gmail.com
Thu Apr 3 15:55:04 PDT 2014


On Thu, Apr 3, 2014 at 3:36 PM, Rui Ueyama <ruiu at google.com> wrote:
> Author: ruiu
> Date: Thu Apr  3 17:36:55 2014
> New Revision: 205576
>
> URL: http://llvm.org/viewvc/llvm-project?rev=205576&view=rev
> Log:
> Replace a recursion with a loop for speed.
>
> Modified:
>     lld/trunk/lib/Core/SymbolTable.cpp
>
> Modified: lld/trunk/lib/Core/SymbolTable.cpp
> URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/SymbolTable.cpp?rev=205576&r1=205575&r2=205576&view=diff
> ==============================================================================
> --- lld/trunk/lib/Core/SymbolTable.cpp (original)
> +++ lld/trunk/lib/Core/SymbolTable.cpp Thu Apr  3 17:36:55 2014
> @@ -379,11 +379,13 @@ void SymbolTable::addReplacement(const A
>  }
>
>  const Atom *SymbolTable::replacement(const Atom *atom) {
> -  AtomToAtom::iterator pos = _replacedAtoms.find(atom);
> -  if (pos == _replacedAtoms.end())
> -    return atom;
> -  // might be chain, recurse to end
> -  return replacement(pos->second);
> +  for (;;) {
> +    AtomToAtom::iterator pos = _replacedAtoms.find(atom);
> +    if (pos == _replacedAtoms.end())
> +      return atom;
> +    // might be chain, recurse to end

Not sure if you want to update this comment now that the algorithm
isn't stack recursive ("recurse" might still be the most suitable way
to describe this algorithm, I don't know)

> +    atom = pos->second;
> +  }
>  }
>
>  unsigned int SymbolTable::size() {
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits



More information about the llvm-commits mailing list