[lld] r177588 - [SymbolTable][Perf] Use hash_combine instead of a custom hash, also use memcmp.
Michael J. Spencer
bigcheesegs at gmail.com
Wed Mar 20 15:18:22 PDT 2013
Author: mspencer
Date: Wed Mar 20 17:18:22 2013
New Revision: 177588
URL: http://llvm.org/viewvc/llvm-project?rev=177588&view=rev
Log:
[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.
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=177588&r1=177587&r2=177588&view=diff
==============================================================================
--- lld/trunk/lib/Core/SymbolTable.cpp (original)
+++ lld/trunk/lib/Core/SymbolTable.cpp Wed Mar 20 17:18:22 2013
@@ -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 &
}
}
-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::isEqu
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) {
More information about the llvm-commits
mailing list