From 654a85e2ee08367dfbd391440fe5e69d2b3cde4f Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Mon, 23 Feb 2015 16:41:36 +0000 Subject: Sync the __builtin_expects for our 3 quadratically probed hash table implementations. This assumes that a) finding the bucket containing the value is LIKELY b) finding an empty bucket is LIKELY c) growing the table is UNLIKELY I also switched the a) and b) cases for SmallPtrSet as we seem to use the set mostly more for insertion than for checking existence. In a simple benchmark consisting of 2^21 insertions of 2^20 unique pointers into a DenseMap or SmallPtrSet a few percent speedup on average, but nothing statistically significant. llvm-svn: 230232 --- llvm/lib/Support/StringMap.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'llvm/lib/Support/StringMap.cpp') diff --git a/llvm/lib/Support/StringMap.cpp b/llvm/lib/Support/StringMap.cpp index ddb73494ff5..7be946642d9 100644 --- a/llvm/lib/Support/StringMap.cpp +++ b/llvm/lib/Support/StringMap.cpp @@ -188,9 +188,10 @@ unsigned StringMapImpl::RehashTable(unsigned BucketNo) { // If the hash table is now more than 3/4 full, or if fewer than 1/8 of // the buckets are empty (meaning that many are filled with tombstones), // grow/rehash the table. - if (NumItems*4 > NumBuckets*3) { + if (LLVM_UNLIKELY(NumItems * 4 > NumBuckets * 3)) { NewSize = NumBuckets*2; - } else if (NumBuckets-(NumItems+NumTombstones) <= NumBuckets/8) { + } else if (LLVM_UNLIKELY(NumBuckets - (NumItems + NumTombstones) <= + NumBuckets / 8)) { NewSize = NumBuckets; } else { return BucketNo; -- cgit v1.2.3