From: serge-sans-paille Date: Mon, 1 Jun 2020 05:49:19 +0000 (+0200) Subject: Improve SmallPtrSetImpl::count implementation X-Git-Tag: llvmorg-12-init~4538 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=11efb0837c897c709ae162eb5ebabb460fc537ff;p=platform%2Fupstream%2Fllvm.git Improve SmallPtrSetImpl::count implementation 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. Differential Revision: https://reviews.llvm.org/D80708 --- diff --git a/llvm/include/llvm/ADT/SmallPtrSet.h b/llvm/include/llvm/ADT/SmallPtrSet.h index 05073cf..0ab05cf 100644 --- a/llvm/include/llvm/ADT/SmallPtrSet.h +++ b/llvm/include/llvm/ADT/SmallPtrSet.h @@ -372,7 +372,9 @@ public: 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))); }