[llvm] r197879 - The count() function for STL datatypes returns unsigned, even
Yaron Keren
yaron.keren at gmail.com
Sun Dec 22 04:04:24 PST 2013
Author: yrnkrn
Date: Sun Dec 22 06:04:23 2013
New Revision: 197879
URL: http://llvm.org/viewvc/llvm-project?rev=197879&view=rev
Log:
The count() function for STL datatypes returns unsigned, even
where it's only bool-like 1/0 result like std::set.count().
Some of the LLVM ADT already return unsigned count(), while
others return bool count().
This patch modifies SmallPtrSet, SmallSet, SparseSet count()
to return unsigned instead of bool:
1 instead of true
0 instead of false
More ADT to follow.
Modified:
llvm/trunk/include/llvm/ADT/SmallPtrSet.h
llvm/trunk/include/llvm/ADT/SmallSet.h
llvm/trunk/include/llvm/ADT/SparseSet.h
llvm/trunk/include/llvm/ADT/StringMap.h
Modified: llvm/trunk/include/llvm/ADT/SmallPtrSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallPtrSet.h?rev=197879&r1=197878&r2=197879&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallPtrSet.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallPtrSet.h Sun Dec 22 06:04:23 2013
@@ -271,9 +271,9 @@ public:
return erase_imp(PtrTraits::getAsVoidPointer(Ptr));
}
- /// count - Return true if the specified pointer is in the set.
- bool count(PtrType Ptr) const {
- return count_imp(PtrTraits::getAsVoidPointer(Ptr));
+ /// count - Return 1 if the specified pointer is in the set, 0 otherwise.
+ unsigned count(PtrType Ptr) const {
+ return count_imp(PtrTraits::getAsVoidPointer(Ptr)) ? 1 : 0;
}
template <typename IterT>
Modified: llvm/trunk/include/llvm/ADT/SmallSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SmallSet.h?rev=197879&r1=197878&r2=197879&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SmallSet.h (original)
+++ llvm/trunk/include/llvm/ADT/SmallSet.h Sun Dec 22 06:04:23 2013
@@ -47,11 +47,11 @@ public:
return isSmall() ? Vector.size() : Set.size();
}
- /// count - Return true if the element is in the set.
- bool count(const T &V) const {
+ /// count - Return 1 if the element is in the set, 0 otherwise.
+ unsigned count(const T &V) const {
if (isSmall()) {
// Since the collection is small, just do a linear search.
- return vfind(V) != Vector.end();
+ return vfind(V) == Vector.end() ? 0 : 1;
} else {
return Set.count(V);
}
Modified: llvm/trunk/include/llvm/ADT/SparseSet.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/SparseSet.h?rev=197879&r1=197878&r2=197879&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/SparseSet.h (original)
+++ llvm/trunk/include/llvm/ADT/SparseSet.h Sun Dec 22 06:04:23 2013
@@ -227,10 +227,11 @@ public:
return const_cast<SparseSet*>(this)->findIndex(KeyIndexOf(Key));
}
- /// count - Returns true if this set contains an element identified by Key.
+ /// count - Returns 1 if this set contains an element identified by Key,
+ /// 0 otherwise.
///
- bool count(const KeyT &Key) const {
- return find(Key) != end();
+ unsigned count(const KeyT &Key) const {
+ return find(Key) == end() ? 0 : 1;
}
/// insert - Attempts to insert a new element.
Modified: llvm/trunk/include/llvm/ADT/StringMap.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/ADT/StringMap.h?rev=197879&r1=197878&r2=197879&view=diff
==============================================================================
--- llvm/trunk/include/llvm/ADT/StringMap.h (original)
+++ llvm/trunk/include/llvm/ADT/StringMap.h Sun Dec 22 06:04:23 2013
@@ -313,6 +313,7 @@ public:
return GetOrCreateValue(Key).getValue();
}
+ /// count - Return 1 if the element is in the map, 0 otherwise.
size_type count(StringRef Key) const {
return find(Key) == end() ? 0 : 1;
}
More information about the llvm-commits
mailing list