[PATCH] D80708: Improve SmallPtrSetImpl::count implementation
serge via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu May 28 04:18:33 PDT 2020
serge-sans-paille created this revision.
serge-sans-paille added reviewers: yaron.keren, dexonsmith, bkramer.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Relying on the `find` method implies a roundtrip to the iterator world, which is not costless because iterator creation involves a few check to ensure the iterator is in a valid position (through the `SmallPtrSetIteratorImpl::AdvanceIfNotValid` method). It turns out that the result of ` SmallPtrSetImpl::find_imp` is either valid or the EndPointer, so there's no need to go through that abstraction, and the compiler cannot guess it.
https://reviews.llvm.org/D80708
Files:
llvm/include/llvm/ADT/SmallPtrSet.h
Index: llvm/include/llvm/ADT/SmallPtrSet.h
===================================================================
--- llvm/include/llvm/ADT/SmallPtrSet.h
+++ llvm/include/llvm/ADT/SmallPtrSet.h
@@ -372,7 +372,9 @@
return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
}
/// count - Return 1 if the specified pointer is in the set, 0 otherwise.
- size_type count(ConstPtrType Ptr) const { return find(Ptr) != end() ? 1 : 0; }
+ size_type count(ConstPtrType Ptr) const {
+ return find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)) != EndPointer();
+ }
iterator find(ConstPtrType Ptr) const {
return makeIterator(find_imp(ConstPtrTraits::getAsVoidPointer(Ptr)));
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80708.266804.patch
Type: text/x-patch
Size: 682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200528/1d1e61af/attachment-0001.bin>
More information about the llvm-commits
mailing list