I plan to use one overload in an llvm-objcopy patch.
Details
Diff Detail
- Repository
- rL LLVM
- Build Status
Buildable 38325 Build 38324: arc lint + arc unit
Event Timeline
include/llvm/ADT/DenseMap.h | ||
---|---|---|
219–222 | This looks accidentally recursive to me, and I don't see test coverage for it. |
Fix std::pair<iterator, bool> insert_or_assign(const KeyT &Key, V &&Val)
and add tests
include/llvm/ADT/DenseMap.h | ||
---|---|---|
206–231 | Is this significantly cheaper than - say, try_emplace + assignment? (the latter seems like it'd keep the implementation simpler/less risky) auto {Iter, Inserted} = m.try_emplace(key, value); if (!Inserted) Iter->second = value & at that point, should it perhaps be a utility, rather than reimplementing it in every container? | |
226–227 | This doesn't look like assignment - seems like it's inconsistent with the name of the function and the functionality of the standard version of this function? | |
unittests/ADT/DenseMapTest.cpp | ||
200 | I'd probably test this with something simpler than std::unique_ptr - to make the test more targeted/clear as to what it's testing. | |
203–204 | Does this leak memory? |
Address review comments
include/llvm/ADT/DenseMap.h | ||
---|---|---|
206–231 | Thanks! I can do: BucketT *B; bool Added = !LookupBucketFor(Key, B); if (Added) B = InsertIntoBucket(B, std::move(Key), std::forward<V>(Val)); else B->getSecond() = std::forward<V>(Val); return std::make_pair(makeIterator(B, getBucketsEnd(), *this, true), Added); but that seems no better than: auto Ret = try_emplace(std::move(Key), std::forward<V>(Val)); if (!Ret.second) Ret.first->second = std::forward<V>(Val); return Ret; So I'll use the simple version. | |
unittests/ADT/DenseMapTest.cpp | ||
200 | I agree it is less clear but it has a nice property. std::unique_ptr<int> as the value type can be used to detect memory leaks in a -DLLVM_USE_SANITIZER=Address build. |
This looks accidentally recursive to me, and I don't see test coverage for it.