Skip to content

Commit

Permalink
Bug 1290035 - Remove the explicit Type parameter to MakeEnumeratedRan…
Browse files Browse the repository at this point in the history
…ge. r=Waldo

MozReview-Commit-ID: BtFVn9pTQpU
  • Loading branch information
heycam committed Jul 28, 2016
1 parent bf7e32c commit fc4b586
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 71 deletions.
12 changes: 6 additions & 6 deletions js/src/gc/Heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,28 +183,28 @@ IsShapeAllocKind(AllocKind kind)

// Returns a sequence for use in a range-based for loop,
// to iterate over all alloc kinds.
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::FIRST, AllocKind::LIMIT))
inline decltype(mozilla::MakeEnumeratedRange(AllocKind::FIRST, AllocKind::LIMIT))
AllAllocKinds()
{
return mozilla::MakeEnumeratedRange<int>(AllocKind::FIRST, AllocKind::LIMIT);
return mozilla::MakeEnumeratedRange(AllocKind::FIRST, AllocKind::LIMIT);
}

// Returns a sequence for use in a range-based for loop,
// to iterate over all object alloc kinds.
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT_FIRST, AllocKind::OBJECT_LIMIT))
inline decltype(mozilla::MakeEnumeratedRange(AllocKind::OBJECT_FIRST, AllocKind::OBJECT_LIMIT))
ObjectAllocKinds()
{
return mozilla::MakeEnumeratedRange<int>(AllocKind::OBJECT_FIRST, AllocKind::OBJECT_LIMIT);
return mozilla::MakeEnumeratedRange(AllocKind::OBJECT_FIRST, AllocKind::OBJECT_LIMIT);
}

// Returns a sequence for use in a range-based for loop,
// to iterate over alloc kinds from |first| to |limit|, exclusive.
inline decltype(mozilla::MakeEnumeratedRange<int>(AllocKind::FIRST, AllocKind::LIMIT))
inline decltype(mozilla::MakeEnumeratedRange(AllocKind::FIRST, AllocKind::LIMIT))
SomeAllocKinds(AllocKind first = AllocKind::FIRST, AllocKind limit = AllocKind::LIMIT)
{
MOZ_ASSERT(IsAllocKind(first), "|first| is not a valid AllocKind!");
MOZ_ASSERT(IsAllocKind(limit), "|limit| is not a valid AllocKind!");
return mozilla::MakeEnumeratedRange<int>(first, limit);
return mozilla::MakeEnumeratedRange(first, limit);
}

// AllAllocKindArray<ValueType> gives an enumerated array of ValueTypes,
Expand Down
116 changes: 51 additions & 65 deletions mfbt/EnumeratedRange.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,26 @@
#ifndef mozilla_EnumeratedRange_h
#define mozilla_EnumeratedRange_h

#include "mozilla/IntegerTypeTraits.h"
#include <type_traits>

#include "mozilla/ReverseIterator.h"

namespace mozilla {

namespace detail {

template<typename IntTypeT, typename EnumTypeT>
template<typename EnumTypeT>
class EnumeratedIterator
{
public:
typedef typename std::underlying_type<EnumTypeT>::type IntTypeT;

template<typename EnumType>
explicit EnumeratedIterator(EnumType aCurrent)
: mCurrent(aCurrent) { }

template<typename IntType, typename EnumType>
explicit EnumeratedIterator(const EnumeratedIterator<IntType, EnumType>& aOther)
template<typename EnumType>
explicit EnumeratedIterator(const EnumeratedIterator<EnumType>& aOther)
: mCurrent(aOther.mCurrent) { }

EnumTypeT operator*() const { return mCurrent; }
Expand Down Expand Up @@ -68,77 +71,77 @@ class EnumeratedIterator

/* Comparison operators */

template<typename IntType, typename EnumType>
friend bool operator==(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2);
template<typename IntType, typename EnumType>
friend bool operator!=(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2);
template<typename IntType, typename EnumType>
friend bool operator<(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2);
template<typename IntType, typename EnumType>
friend bool operator<=(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2);
template<typename IntType, typename EnumType>
friend bool operator>(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2);
template<typename IntType, typename EnumType>
friend bool operator>=(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2);
template<typename EnumType>
friend bool operator==(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2);
template<typename EnumType>
friend bool operator!=(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2);
template<typename EnumType>
friend bool operator<(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2);
template<typename EnumType>
friend bool operator<=(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2);
template<typename EnumType>
friend bool operator>(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2);
template<typename EnumType>
friend bool operator>=(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2);

private:
EnumTypeT mCurrent;
};

template<typename IntType, typename EnumType>
bool operator==(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2)
template<typename EnumType>
bool operator==(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2)
{
return aIter1.mCurrent == aIter2.mCurrent;
}

template<typename IntType, typename EnumType>
bool operator!=(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2)
template<typename EnumType>
bool operator!=(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2)
{
return aIter1.mCurrent != aIter2.mCurrent;
}

template<typename IntType, typename EnumType>
bool operator<(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2)
template<typename EnumType>
bool operator<(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2)
{
return aIter1.mCurrent < aIter2.mCurrent;
}

template<typename IntType, typename EnumType>
bool operator<=(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2)
template<typename EnumType>
bool operator<=(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2)
{
return aIter1.mCurrent <= aIter2.mCurrent;
}

template<typename IntType, typename EnumType>
bool operator>(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2)
template<typename EnumType>
bool operator>(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2)
{
return aIter1.mCurrent > aIter2.mCurrent;
}

template<typename IntType, typename EnumType>
bool operator>=(const EnumeratedIterator<IntType, EnumType>& aIter1,
const EnumeratedIterator<IntType, EnumType>& aIter2)
template<typename EnumType>
bool operator>=(const EnumeratedIterator<EnumType>& aIter1,
const EnumeratedIterator<EnumType>& aIter2)
{
return aIter1.mCurrent >= aIter2.mCurrent;
}

template<typename IntTypeT, typename EnumTypeT>
template<typename EnumTypeT>
class EnumeratedRange
{
public:
typedef EnumeratedIterator<IntTypeT, EnumTypeT> iterator;
typedef EnumeratedIterator<IntTypeT, EnumTypeT> const_iterator;
typedef EnumeratedIterator<EnumTypeT> iterator;
typedef EnumeratedIterator<EnumTypeT> const_iterator;
typedef ReverseIterator<iterator> reverse_iterator;
typedef ReverseIterator<const_iterator> const_reverse_iterator;

Expand Down Expand Up @@ -171,38 +174,21 @@ class EnumeratedRange
#endif

// Create a range to iterate from aBegin to aEnd, exclusive.
//
// (Once we can rely on std::underlying_type, we can remove the IntType
// template parameter.)
template<typename IntType, typename EnumType>
inline detail::EnumeratedRange<IntType, EnumType>
template<typename EnumType>
inline detail::EnumeratedRange<EnumType>
MakeEnumeratedRange(EnumType aBegin, EnumType aEnd)
{
#ifdef DEBUG
typedef typename MakeUnsigned<IntType>::Type UnsignedType;
#endif
static_assert(sizeof(IntType) >= sizeof(EnumType),
"IntType should be at least as big as EnumType!");
MOZ_ASSERT(aBegin <= aEnd, "Cannot generate invalid, unbounded range!");
MOZ_ASSERT_IF(aBegin < EnumType(0), IsSigned<IntType>::value);
MOZ_ASSERT_IF(aBegin >= EnumType(0) && IsSigned<IntType>::value,
UnsignedType(aEnd) <= UnsignedType(MaxValue<IntType>::value));
return detail::EnumeratedRange<IntType, EnumType>(aBegin, aEnd);
return detail::EnumeratedRange<EnumType>(aBegin, aEnd);
}

// Create a range to iterate from EnumType(0) to aEnd, exclusive. EnumType(0)
// should exist, but note that there is no way for us to ensure that it does!
// Since the enumeration starts at EnumType(0), we know for sure that the values
// will be in range of our deduced IntType.
template<typename EnumType>
inline detail::EnumeratedRange<
typename UnsignedStdintTypeForSize<sizeof(EnumType)>::Type,
EnumType>
inline detail::EnumeratedRange<EnumType>
MakeEnumeratedRange(EnumType aEnd)
{
return MakeEnumeratedRange<
typename UnsignedStdintTypeForSize<sizeof(EnumType)>::Type>(EnumType(0),
aEnd);
return MakeEnumeratedRange(EnumType(0), aEnd);
}

#ifdef __GNUC__
Expand Down

0 comments on commit fc4b586

Please sign in to comment.