diff options
author | Michael J. Spencer <bigcheesegs@gmail.com> | 2013-03-20 22:18:22 +0000 |
---|---|---|
committer | Michael J. Spencer <bigcheesegs@gmail.com> | 2013-03-20 22:18:22 +0000 |
commit | 67f25272f193c4263f0cc29ee1af764c161ffb97 (patch) | |
tree | 739212c004702eef827432392e01c6a53be67417 /lld/lib/Core/SymbolTable.cpp | |
parent | d14b6ef6efeeb6ffaa262734181d3291f251638e (diff) | |
download | bcm5719-llvm-67f25272f193c4263f0cc29ee1af764c161ffb97.tar.gz bcm5719-llvm-67f25272f193c4263f0cc29ee1af764c161ffb97.zip |
[SymbolTable][Perf] Use hash_combine instead of a custom hash, also use memcmp.
ArrayRef<uint8_t>::equals(); lowers to a byte compare loop :(.
TODO: Figure out if we are getting hash collisions, or just have a lot of equal
content. Also test if crypto hashing the content instead of full compare is
better.
llvm-svn: 177588
Diffstat (limited to 'lld/lib/Core/SymbolTable.cpp')
-rw-r--r-- | lld/lib/Core/SymbolTable.cpp | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/lld/lib/Core/SymbolTable.cpp b/lld/lib/Core/SymbolTable.cpp index 9fd4eb26354..36e52d8ed07 100644 --- a/lld/lib/Core/SymbolTable.cpp +++ b/lld/lib/Core/SymbolTable.cpp @@ -22,6 +22,7 @@ #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseMapInfo.h" +#include "llvm/ADT/Hashing.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/raw_ostream.h" @@ -255,22 +256,16 @@ void SymbolTable::addByName(const Atom & newAtom) { } } -unsigned SymbolTable::AtomMappingInfo::getHashValue(const DefinedAtom * const atom) { - unsigned hash = atom->size(); - if ( atom->contentType() != DefinedAtom::typeZeroFill ) { - ArrayRef<uint8_t> content = atom->rawContent(); - for (unsigned int i=0; i < content.size(); ++i) { - hash = hash * 33 + content[i]; - } - } - hash &= 0x00FFFFFF; - hash |= ((unsigned)atom->contentType()) << 24; - //fprintf(stderr, "atom=%p, hash=0x%08X\n", atom, hash); - return hash; +unsigned SymbolTable::AtomMappingInfo::getHashValue(const DefinedAtom *atom) { + auto content = atom->rawContent(); + return llvm::hash_combine(atom->size(), + atom->contentType(), + llvm::hash_combine_range(content.begin(), + content.end())); } bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l, - const DefinedAtom * const r) { + const DefinedAtom * const r) { if ( l == r ) return true; if ( l == getEmptyKey() ) @@ -288,7 +283,7 @@ bool SymbolTable::AtomMappingInfo::isEqual(const DefinedAtom * const l, return false; ArrayRef<uint8_t> lc = l->rawContent(); ArrayRef<uint8_t> rc = r->rawContent(); - return lc.equals(rc); + return memcmp(lc.data(), rc.data(), lc.size()) == 0; } void SymbolTable::addByContent(const DefinedAtom & newAtom) { |