diff options
author | Chris Lattner <sabre@nondot.org> | 2008-07-02 05:30:45 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2008-07-02 05:30:45 +0000 |
commit | 509e4f30e85355540dc3bf52629d2356cfd4c1bf (patch) | |
tree | a87b83c20c0b923b32dffd0a45af770b9f80fa60 /include/llvm/ADT/StringMap.h | |
parent | fce6e546aab64602c41eeb83381b7617f97d0069 (diff) | |
download | external_llvm-509e4f30e85355540dc3bf52629d2356cfd4c1bf.tar.gz external_llvm-509e4f30e85355540dc3bf52629d2356cfd4c1bf.tar.bz2 external_llvm-509e4f30e85355540dc3bf52629d2356cfd4c1bf.zip |
optimize StringMap::clear
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@53009 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/llvm/ADT/StringMap.h')
-rw-r--r-- | include/llvm/ADT/StringMap.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/include/llvm/ADT/StringMap.h b/include/llvm/ADT/StringMap.h index 7189931abb..6675d04f8d 100644 --- a/include/llvm/ADT/StringMap.h +++ b/include/llvm/ADT/StringMap.h @@ -335,8 +335,16 @@ public: // clear - Empties out the StringMap void clear() { - while (!empty()) - erase(begin()); + if (empty()) return; + + // Zap all values, resetting the keys back to non-present (not tombstone), + // which is safe because we're removing all elements. + for (ItemBucket *I = TheTable, *E = TheTable+NumBuckets; I != E; ++I) { + if (I->Item && I->Item != getTombstoneVal()) { + static_cast<MapEntryTy*>(I->Item)->Destroy(Allocator); + I->Item = 0; + } + } } /// GetOrCreateValue - Look up the specified key in the table. If a value @@ -398,10 +406,7 @@ public: } ~StringMap() { - for (ItemBucket *I = TheTable, *E = TheTable+NumBuckets; I != E; ++I) { - if (I->Item && I->Item != getTombstoneVal()) - static_cast<MapEntryTy*>(I->Item)->Destroy(Allocator); - } + clear(); free(TheTable); } private: |