Commit 8939e97c authored by Kevin Modzelewski's avatar Kevin Modzelewski

Fix some other misc issues

- 64 bit hashes in a couple more places
- insert-then-grow, instead of previously doing grow-then-insert
  (changes the order of reinsertion during the grow)
parent 498168d8
......@@ -446,6 +446,7 @@ private:
TheBucket->getFirst() = Key;
new (&TheBucket->getSecond()) ValueT(Value);
TheBucket = growMaybe(Key, TheBucket);
return TheBucket;
}
......@@ -455,6 +456,7 @@ private:
TheBucket->getFirst() = Key;
new (&TheBucket->getSecond()) ValueT(std::move(Value));
TheBucket = growMaybe(Key, TheBucket);
return TheBucket;
}
......@@ -463,6 +465,21 @@ private:
TheBucket->getFirst() = std::move(Key);
new (&TheBucket->getSecond()) ValueT(std::move(Value));
TheBucket = growMaybe(Key, TheBucket);
return TheBucket;
}
BucketT* growMaybe(const KeyT& Key, BucketT *TheBucket) {
unsigned NewNumEntries = getNumEntries();
unsigned NumBuckets = getNumBuckets();
if (LLVM_UNLIKELY(NewNumEntries * 3 >= NumBuckets * 2)) {
this->grow(NewNumEntries * (NewNumEntries > 50000 ? 2 : 4));
LookupBucketFor(Key, TheBucket);
} else if (LLVM_UNLIKELY(NumBuckets-(NewNumEntries+getNumTombstones()) <=
NumBuckets/8)) {
this->grow(NumBuckets);
LookupBucketFor(Key, TheBucket);
}
return TheBucket;
}
......@@ -478,14 +495,10 @@ private:
// causing infinite loops in lookup.
unsigned NewNumEntries = getNumEntries() + 1;
unsigned NumBuckets = getNumBuckets();
if (LLVM_UNLIKELY(NewNumEntries * 3 >= NumBuckets * 2)) {
if (LLVM_UNLIKELY(NumBuckets == 0)) {
this->grow(NewNumEntries * (NewNumEntries > 50000 ? 2 : 4));
LookupBucketFor(Key, TheBucket);
NumBuckets = getNumBuckets();
} else if (LLVM_UNLIKELY(NumBuckets-(NewNumEntries+getNumTombstones()) <=
NumBuckets/8)) {
this->grow(NumBuckets);
LookupBucketFor(Key, TheBucket);
}
assert(TheBucket);
......
......@@ -33,8 +33,8 @@ template <> struct DenseMapInfo<pyston::BoxedString*> {
return reinterpret_cast<pyston::BoxedString*>(Val);
}
static unsigned getHashValue(pyston::BoxedString* s) { return pyston::strHashUnboxed(s); }
static unsigned getHashValue(llvm::StringRef s) { return pyston::strHashUnboxedStrRef(s); }
static size_t getHashValue(pyston::BoxedString* s) { return pyston::strHashUnboxed(s); }
static size_t getHashValue(llvm::StringRef s) { return pyston::strHashUnboxedStrRef(s); }
static bool isSpecial(pyston::BoxedString* v) { return v == getEmptyKey() || v == getTombstoneKey(); }
static bool isEqual(pyston::BoxedString* lhs, pyston::BoxedString* rhs) {
......
......@@ -1015,7 +1015,7 @@ struct BoxAndHash {
}
static BoxAndHash getEmptyKey() { return BoxAndHash((Box*)-1, 0); }
static BoxAndHash getTombstoneKey() { return BoxAndHash((Box*)-2, 0); }
static unsigned getHashValue(BoxAndHash val) { return val.hash; }
static size_t getHashValue(BoxAndHash val) { return val.hash; }
};
};
// Similar to the incref(Box*) function:
......
......@@ -35,3 +35,5 @@ for i in xrange(100):
pop()
print print_final
print {'logoq': 349, 'kprzd': 301, 'qemgi': 342, 'xpuhv': 310, 'dpmbn': 250, 'trvxs': 264}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment