Bug 1276573 - Add a new constructor for Range<T>. r=Waldo

These new constructor accepts two RangedPtr<T> arguments.

MozReview-Commit-ID: 8a3bYserLMr

--HG--
extra : rebase_source : 216de17b7a51783fe48d604b432d4dc7df6ad6eb
This commit is contained in:
Boris Chiou 2016-05-30 13:58:13 +08:00
parent b7270d91cb
commit c329f132b7
2 changed files with 15 additions and 2 deletions

View File

@ -26,6 +26,14 @@ public:
: mStart(aPtr, aPtr, aPtr + aLength),
mEnd(aPtr + aLength, aPtr, aPtr + aLength)
{}
Range(const RangedPtr<T>& aStart, const RangedPtr<T>& aEnd)
: mStart(aStart.get(), aStart.get(), aEnd.get()),
mEnd(aEnd.get(), aStart.get(), aEnd.get())
{
// Only accept two RangedPtrs within the same range.
aStart.checkIdenticalRange(aEnd);
MOZ_ASSERT(aStart <= aEnd);
}
RangedPtr<T> start() const { return mStart; }
RangedPtr<T> end() const { return mEnd; }

View File

@ -117,6 +117,12 @@ public:
explicit operator bool() const { return mPtr != nullptr; }
void checkIdenticalRange(const RangedPtr<T>& aOther) const
{
MOZ_ASSERT(mRangeStart == aOther.mRangeStart);
MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd);
}
/*
* You can only assign one RangedPtr into another if the two pointers have
* the same valid range:
@ -129,8 +135,7 @@ public:
*/
RangedPtr<T>& operator=(const RangedPtr<T>& aOther)
{
MOZ_ASSERT(mRangeStart == aOther.mRangeStart);
MOZ_ASSERT(mRangeEnd == aOther.mRangeEnd);
checkIdenticalRange(aOther);
mPtr = aOther.mPtr;
checkSanity();
return *this;