Add VectorBase::ConstRange that only gives out `const T&` entries

RESOLVED FIXED in Firefox 39

Status

()

defect
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: fitzgen, Assigned: fitzgen)

Tracking

unspecified
mozilla39
x86
macOS
Points:
---
Dependency tree / graph
Bug Flags:
in-testsuite +

Firefox Tracking Flags

(firefox39 fixed)

Details

Attachments

(1 attachment, 1 obsolete attachment)

VectorBase::Range gives out `T&`, but for cases where consumers shouldn't be able to modify entries, only read them, it doesn't provide any nice guarantees. We should have a VectorBase::ConstRange that only gives out `const T&` entries.

Is there a better (standard-ish for this type of thing?) name than ConstRange?
Comment on attachment 8573439 [details] [diff] [review]
Add VectorBase::ConstRange that gives out |const T&| entries

Review of attachment 8573439 [details] [diff] [review]:
-----------------------------------------------------------------

::: mfbt/Vector.h
@@ +492,5 @@
> +    {
> +      MOZ_ASSERT(aCur <= aEnd);
> +    }
> +
> +  public:

Either include ConstRange() {}, or (more likely) remove Range() {} from the class just above.

@@ +496,5 @@
> +  public:
> +    bool empty() const { return mCur == mEnd; }
> +    size_t remain() const { return PointerRangeSize(mCur, mEnd); }
> +    const T& front() const { MOZ_ASSERT(!empty()); return *mCur; }
> +    void popFront() { MOZ_ASSERT(!empty()); ++mCur; }

Why no popCopyFront?  Seems like it should be fine to include, it's not mutating any members, just making copies of them.
Attachment #8573439 - Flags: review?(jwalden+bmo) → review+
https://hg.mozilla.org/mozilla-central/rev/9da55484cc2d
Status: ASSIGNED → RESOLVED
Closed: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla39
You need to log in before you can comment on or make changes to this bug.