count() patch to unsigned for SmallPtrSet, SmallSet, SparseSet
Yaron Keren
yaron.keren at gmail.com
Sat Dec 21 01:48:43 PST 2013
The count() function for STL datatypes returns unsigned, even where it's
only 1/0 result like std::set. Some of the LLVM ADT already return unsigned
count(), while others still return bool count().
This patch modifies SmallPtrSet, SmallSet, SparseSet :: count() to return
unsigned instead of bool, 1 instead of true and 0 instead of false.
Yaron
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20131221/c7f38fc6/attachment.html>
-------------- next part --------------
Index: SmallPtrSet.h
===================================================================
--- SmallPtrSet.h (revision 197828)
+++ SmallPtrSet.h (working copy)
@@ -271,9 +271,9 @@
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>
Index: SmallSet.h
===================================================================
--- SmallSet.h (revision 197828)
+++ SmallSet.h (working copy)
@@ -47,11 +47,11 @@
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);
}
Index: SparseSet.h
===================================================================
--- SparseSet.h (revision 197828)
+++ SparseSet.h (working copy)
@@ -227,10 +227,11 @@
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.
Index: StringMap.h
===================================================================
--- StringMap.h (revision 197828)
+++ StringMap.h (working copy)
@@ -313,6 +313,7 @@
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 cfe-commits
mailing list