llvm.org GIT mirror llvm / 549896a
[ADT] Add a much simpler loop to DenseMap::clear when the types are POD-like and we can just splat the empty key across memory. Sadly we can't optimize the normal loop well enough because we can't turn the conditional store into an unconditional store according to the memory model. This loop actually showed up in a profile of code that was calling clear as a serious source of time. =[ git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@310189 91177308-0d34-0410-b5e6-96231b3b80d8 Chandler Carruth 2 years ago
1 changed file(s) with 15 addition(s) and 9 deletion(s). Raw diff Collapse all Expand all
106106 }
107107
108108 const KeyT EmptyKey = getEmptyKey(), TombstoneKey = getTombstoneKey();
109 unsigned NumEntries = getNumEntries();
110 for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
111 if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {
112 if (!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
113 P->getSecond().~ValueT();
114 --NumEntries;
109 if (isPodLike::value && isPodLike::value) {
110 // Use a simpler loop when these are trivial types.
111 for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P)
112 P->getFirst() = EmptyKey;
113 } else {
114 unsigned NumEntries = getNumEntries();
115 for (BucketT *P = getBuckets(), *E = getBucketsEnd(); P != E; ++P) {
116 if (!KeyInfoT::isEqual(P->getFirst(), EmptyKey)) {
117 if (!KeyInfoT::isEqual(P->getFirst(), TombstoneKey)) {
118 P->getSecond().~ValueT();
119 --NumEntries;
120 }
121 P->getFirst() = EmptyKey;
115122 }
116 P->getFirst() = EmptyKey;
117123 }
118 }
119 assert(NumEntries == 0 && "Node count imbalance!");
124 assert(NumEntries == 0 && "Node count imbalance!");
125 }
120126 setNumEntries(0);
121127 setNumTombstones(0);
122128 }