aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/ADT/StringMapTest.cpp
AgeCommit message (Collapse)AuthorFilesLines
2025-08-31[ADT] Refactor StringMap iterators (NFC) (#156137)Kazu Hirata1-0/+54
StringMap has four iterator classes: - StringMapIterBase - StringMapIterator - StringMapConstIterator - StringMapKeyIterator This patch consolidates the first three into one class, namely StringMapIterBase, adds a boolean template parameter to indicate desired constness, and then use "using" directives to specialize the common class: using const_iterator = StringMapIterBase<ValueTy, true>; using iterator = StringMapIterBase<ValueTy, false>; just like how we simplified DenseMapIterator. Remarks: - This patch drops CRTP and iterator_facade_base for simplicity. For fairly simple forward iterators, iterator_facade_base doesn't buy us much. We just have to write a few "using" directives and operator!= manually. - StringMapIterBase has a SFINAE-based constructor to construct a const iterator from a non-const one just like DenseMapIterator. - We now rely on compiler-generated copy and assignment operators.
2024-11-02[llvm][ADT] Structured bindings for move-only types in `StringMap` (#114676)Jan Svoboda1-0/+23
This PR implements destructuring of `StringMapEntry<T>` where `T` is a move-only type. Also adds the non-const version.
2024-02-02Reapply "[ADT][StringMap] Add ability to precompute and reuse the string hash"David Blaikie1-0/+11
Reverted due to an internally discovered lld crash, which turned out to be an existing lld bug that got tickled by this changes. That's addressed in dee8786f70a3d62b639113343fa36ef55bdbad63 so let's have another go with this change. Original commit message: Useful for lldb's const string pool, using the hash to determine which string map to lock and query/insert. Derived from https://reviews.llvm.org/D122974 by Luboš Luňák This reverts commit f976719fb2cb23364957e5993f7fc3684ee15391. Effectively reapplying 67c631d283fc96d652304199cd625be426b98f8e.
2023-12-14Revert "[ADT][StringMap] Add ability to precompute and reuse the string hash"David Blaikie1-11/+0
Crash identified internally in lld's use of StringMap in `compareSections`. Will investigate offline before recommitting. This reverts commit 67c631d283fc96d652304199cd625be426b98f8e.
2023-12-12[ADT][StringMap] Add ability to precompute and reuse the string hashDavid Blaikie1-0/+11
Useful for lldb's const string pool, using the hash to determine which string map to lock and query/insert. Derived from https://reviews.llvm.org/D122974 by Luboš Luňák
2023-03-13[ADT] Implement {DenseMap,MapVector,StringMap}::containsKazu Hirata1-0/+2
This patch implements the C++20-style contains() for DenseMap, MapVector, and StringMap. With this patch, every set and map container type that has count() also has contains(). Differential Revision: https://reviews.llvm.org/D145895
2023-02-17[ADT] Fix tests for `StringMap::at` and `DenseMap::at`Ryan Guo1-5/+1
These methods won't assert for release build.
2023-02-17[ADT] Add `at` method (assertive lookup) to DenseMap and StringMapRyan Guo1-0/+16
This patch makes it easier for users when they want to use validated lookup on DenseMap/StringMap as a composable C++ expression. For instance: ``` // instead of if (auto val = map.lookup(key)) return val; assert("..."); // we can write return map.at(key); ``` Differential Revision: https://reviews.llvm.org/D143976
2022-12-25[NFC][ADT] Rename StringMapEntry *Create() into StringMapEntry *create.Alexey Lapshin1-4/+4
2022-12-04[ADT] Enable structured bindings for iterating StringMapBenjamin Kramer1-0/+10
const references only for now, we can add overloads to have a mutable or movable `second` if the need arises.
2022-08-29[llvm][ADT] Fix formatting for files relevant to `StringMap`.Wei Yi Tee1-18/+14
Differential Revision: https://reviews.llvm.org/D132744
2022-08-29Revert "[llvm][ADT] Fix formatting for files relevant to `StringMap`."Wei Yi Tee1-14/+18
This reverts commit d23df9c9e81e186c3218bd924976fbd646f3bad1. Revert due to missing review link.
2022-08-29[llvm][ADT] Fix formatting for files relevant to `StringMap`.Wei Yi Tee1-18/+14
2022-07-12[ADT] Use Empty Base Optimization for AllocatorsNathan James1-0/+4
In D94439, BumpPtrAllocator changed its implementation to use an empty base optimization for the underlying allocator. This patch builds on that by extending its functionality to more classes as well as enabling the underlying allocator to be a reference type, something not currently possible as you can't derive from a reference. The main place this sees use is in StringMaps which often use the default MallocAllocator, yet have to pay the size of a pointer for no reason. Reviewed By: dblaikie Differential Revision: https://reviews.llvm.org/D129206
2022-01-24Move STLFunctionalExtras out of STLExtrasserge-sans-paille1-0/+1
Only using that change in StringRef already decreases the number of preoprocessed lines from 7837621 to 7776151 for LLVMSupport Perhaps more interestingly, it shows that many files were relying on the inclusion of StringRef.h to have the declaration from STLExtras.h. This patch tries hard to patch relevant part of llvm-project impacted by this hidden dependency removal. Potential impact: - "llvm/ADT/StringRef.h" no longer includes <memory>, "llvm/ADT/Optional.h" nor "llvm/ADT/STLExtras.h" Related Discourse thread: https://llvm.discourse.group/t/include-what-you-use-include-cleanup/5831
2021-09-02Reland "Try to unbreak Win build differently after 973519826edb76""Nico Weber1-1/+15
Build should be fixed by https://github.com/llvm/llvm-project/commit/9d22754389 This reverts commit df052e1732ab57f5d9c684ceeaed3ab39073cd9f. Differential Revision: https://reviews.llvm.org/D109181
2021-09-02Revert "Try to unbreak Win build differently after 973519826edb76"Geoffrey Martin-Noble1-15/+1
Breaks the build and failed pre-merge checks: https://buildkite.com/llvm-project/premerge-checks/builds/54930#07373971-3d37-49cf-9def-22c0d724ee23 > llvm-project/lld/wasm/Writer.cpp:521:16: error: non-const lvalue reference to > type 'llvm::StringRef' cannot bind to a temporary of type 'llvm::StringRef' > for (auto &feature : used.keys()) { This reverts commit 5881dcff7e76a68323edc8bb3c6e14420ad9cf7c.
2021-09-02Try to unbreak Win build differently after 973519826edb76Nico Weber1-1/+15
Looks like the MS STL wants StringMapKeyIterator::operator*() to be const. Return the result by copy instead of reference to do that. Assigning to a hash map key iterator doesn't make sense anyways. Also reverts 123f811fe5b0b which is now hopefully no longer needed. Differential Revision: https://reviews.llvm.org/D109167
2021-09-02[clang-cl] Emit nicer warning on unknown /arch: argumentsNico Weber1-0/+7
Now prints the list of known archs. This requires plumbing a Driver arg through a few functions. Also add two more convenience insert() overlods to StringMap. Differential Revision: https://reviews.llvm.org/D109105
2020-06-19[clang-tidy] remove duplicate fixes of alias checkersDaniel1-0/+64
when both a check and its alias are enabled, we should only take the fixes of one of them and not both. This patch fixes bug 45577 https://bugs.llvm.org/show_bug.cgi?id=45577 Reviewed By: aaron.ballman, njames93 Differential Revision: https://reviews.llvm.org/D80753
2020-05-02[Allocator] Make Deallocate() pass alignment and make it use (de)allocate_bufferBenjamin Kramer1-1/+1
This lets it use sized deallocation and make more efficient alignment decisions. Also adjust BumpPtrAllocator to always allocate at alignof(std::max_align_t).
2020-04-12clang format one more line.Chris Lattner1-1/+1
2020-04-12NFC: Clean up the implementation of StringPool a bit, and remove dependence ↵Chris Lattner1-5/+7
on some "implicitly MallocAllocator" based methods on StringMapEntry. This allows reducing the #includes in StringMapEntry.h. Summary: StringPool has many caveats and isn't used in the monorepo. I will propose removing it as a patch separate from this refactoring patch. Reviewers: rriddle Subscribers: hiraditya, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D77976
2019-09-25[ADT] Add StringMap::insert_or_assignFangrui Song1-0/+31
Summary: Similar to std::unordered_map::insert_or_assign Reviewers: alexshap, bkramer, dblaikie, lhames Subscribers: jkorous, dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67668 llvm-svn: 372813
2019-06-07[ADT] Enable set_difference() to be used on StringSetMichael Pozulp1-15/+0
Summary: Re-land r362766 after it was reverted in r362823. Reviewers: jhenderson, dsanders, aaron.ballman, MatzeB, lhames, dblaikie Reviewed By: dblaikie Subscribers: smeenai, mgrang, mgorny, dexonsmith, kristina, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62369 llvm-svn: 362835
2019-06-07Revert "[ADT] Enable set_difference() to be used on StringSet"Vlad Tsyrklevich1-0/+15
This reverts commit 0bddef79019a23ab14fcdb27028e55e484674c88, it was causing ASan failures on the sanitizer bots: http://lab.llvm.org:8011/builders/sanitizer-x86_64-linux-fast/builds/32800 llvm-svn: 362823
2019-06-07[ADT] Enable set_difference() to be used on StringSetMichael Pozulp1-15/+0
Subscribers: mgorny, mgrang, dexonsmith, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D62992 llvm-svn: 362766
2019-01-19Update the file headers across all of the LLVM projects in the monorepoChandler Carruth1-4/+3
to reflect the new license. We understand that people may be surprised that we're moving the header entirely to discuss the new license. We checked this carefully with the Foundation's lawyer and we believe this is the correct approach. Essentially, all code in the project is now made available by the LLVM project under our new license, so you will see that the license headers include that license only. Some of our contributors have contributed code under our old license, and accordingly, we have retained a copy of our old license notice in the top-level files in each project and repository. llvm-svn: 351636
2018-09-27llvm::sort(C.begin(), C.end(), ...) -> llvm::sort(C, ...)Fangrui Song1-2/+2
Summary: The convenience wrapper in STLExtras is available since rL342102. Reviewers: dblaikie, javed.absar, JDevlieghere, andreadb Subscribers: MatzeB, sanjoy, arsenm, dschuff, mehdi_amini, sdardis, nemanjai, jvesely, nhaehnle, sbc100, jgravelle-google, eraman, aheejin, kbarton, JDevlieghere, javed.absar, gbedwell, jrtc27, mgrang, atanasyan, steven_wu, george.burgess.iv, dexonsmith, kristina, jsji, llvm-commits Differential Revision: https://reviews.llvm.org/D52573 llvm-svn: 343163
2018-04-07[unittests] Change std::sort to llvm::sort in response to r327219Mandeep Singh Grang1-2/+2
r327219 added wrappers to std::sort which randomly shuffle the container before sorting. This will help in uncovering non-determinism caused due to undefined sorting order of objects having the same key. To make use of that infrastructure we need to invoke llvm::sort instead of std::sort. Note: This patch is one of a series of patches to replace *all* std::sort to llvm::sort. Refer the comments section in D44363 for a list of all the required patches. llvm-svn: 329475
2018-01-11Use size_t to represent the size of a StringMapEntry length and alignment ↵Aaron Ballman1-0/+40
rather than unsigned. Patch by Matt Davis. llvm-svn: 322305
2017-03-31Spelling mistakes in comments. NFCI.Simon Pilgrim1-1/+1
llvm-svn: 299197
2017-03-21Resubmit "Improve StringMap iterator support."Zachary Turner1-0/+29
The issue was trying to advance past the end of the iterator when computing the end() iterator. llvm-svn: 298461
2017-03-21Revert "Improve StringMap iterator support."Zachary Turner1-29/+0
This is causing crashes in clang, so reverting until the problem is figured out. llvm-svn: 298440
2017-03-21Improve StringMap iterator support.Zachary Turner1-0/+29
StringMap's iterators did not support LLVM's iterator_facade_base, which made it unusable in various STL algorithms or with some of our range adapters. This patch makes both StringMapConstIterator as well as StringMapIterator support iterator_facade_base. With this in place, it is easy to make an iterator adapter that iterates over only keys, and whose value_type is StringRef. So I add StringMapKeyIterator as well, and provide the method StringMap::keys() that returns a range that can be iterated. Differential Revision: https://reviews.llvm.org/D31171 llvm-svn: 298436
2016-07-21Rename StringMap::emplace_second to try_emplace.Benjamin Kramer1-1/+1
Coincidentally this function maps to the C++17 try_emplace. Rename it for consistentcy with C++17 std::map. NFC. llvm-svn: 276276
2016-04-16Remove some unneeded headers and replace some headers with forward class ↵Mehdi Amini1-1/+2
declarations (NFC) Differential Revision: http://reviews.llvm.org/D19154 Patch by Eugene Kosov <claprix@yandex.ru> From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 266524
2016-03-30Add a copy constructor to StringMapHal Finkel1-0/+27
There is code under review that requires StringMap to have a copy constructor, and this makes StringMap more consistent with our other containers (like DenseMap) that have copy constructors. Differential Revision: http://reviews.llvm.org/D18506 llvm-svn: 264906
2016-03-25StringMap/DenseMap unittests: use piecewise_construct and ensure no copy occurs.Mehdi Amini1-11/+6
This makes us no longer relying on move-construction elision by the compiler. Suggested by D. Blaikie. From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 264475
2016-03-25Improve StringMap unittests: reintroduce move count, but shield against ↵Mehdi Amini1-5/+12
std::pair internals From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 264418
2016-03-25Ensure that the StringMap does not grow during the test for ↵Mehdi Amini1-0/+3
pre-allocation/reserve From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 264416
2016-03-25Disable counting the number of move in the unittest, it seems to rely on ↵Mehdi Amini1-1/+3
move-construction elision From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 264412
2016-03-25Query the StringMap only once when creating MDString (NFC)Mehdi Amini1-14/+47
Summary: Loading IR with debug info improves MDString::get() from 19ms to 10ms. This is a rework of D16597 with adding an "emplace" method on the StringMap to avoid requiring the MDString move ctor to be public. Reviewers: dexonsmith Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D17920 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 264386
2016-03-25Adjust initial size in StringMap constructor to guarantee no grow()Mehdi Amini1-3/+42
Summary: StringMap ctor accepts an initialize size, but expect it to be rounded to the next power of 2. The ctor can handle that directly instead of expecting clients to round it. Also, since the map will resize itself when 75% full, take this into account an initialize a larger initial size to avoid any growth. Reviewers: dblaikie Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D18344 From: Mehdi Amini <mehdi.amini@apple.com> llvm-svn: 264385
2015-02-15Removing LLVM_DELETED_FUNCTION, as MSVC 2012 was the last reason for ↵Aaron Ballman1-4/+4
requiring the macro. NFC; LLVM edition. llvm-svn: 229340
2014-11-19Remove StringMap::GetOrCreateValue in favor of StringMap::insertDavid Blaikie1-6/+4
Having two ways to do this doesn't seem terribly helpful and consistently using the insert version (which we already has) seems like it'll make the code easier to understand to anyone working with standard data structures. (I also updated many references to the Entry's key and value to use first() and second instead of getKey{Data,Length,} and get/setValue - for similar consistency) Also removes the GetOrCreateValue functions so there's less surface area to StringMap to fix/improve/change/accommodate move semantics, etc. llvm-svn: 222319
2014-11-14StringMap: Test and finish off supporting perfectly forwarded values in ↵David Blaikie1-1/+15
StringMap operations. Followup to r221946. llvm-svn: 221958
2014-06-23Recommit 211309 (StringMap::insert), reverted in 211328 due to issues with ↵David Blaikie1-2/+40
private, but non-deleted, move members. Certain versions of GCC (~4.7) couldn't handle the SFINAE on access control, but with "= delete" (hidden behind a macro for portability) this issue is worked around/addressed. Patch by Agustín Bergé llvm-svn: 211525
2014-06-20Revert "Add StringMap::insert(pair) consistent with the standard associative ↵Rafael Espindola1-38/+0
container concept." This reverts commit r211309. It looks like it broke some bots: http://lab.llvm.org:8011/builders/clang-x86_64-ubuntu-gdb-75/builds/15563/steps/compile/logs/stdio llvm-svn: 211328
2014-06-19Add StringMap::insert(pair) consistent with the standard associative ↵David Blaikie1-0/+38
container concept. Patch by Agustín Bergé. llvm-svn: 211309