Closed
Bug 1247412
Opened 9 years ago
Closed 9 years ago
Add a `reverse` method to `mozilla::Vector`
Categories
(Core :: MFBT, defect)
Core
MFBT
Tracking
()
RESOLVED
FIXED
mozilla47
Tracking | Status | |
---|---|---|
firefox47 | --- | fixed |
People
(Reporter: fitzgen, Assigned: fitzgen)
References
Details
Attachments
(1 file, 1 obsolete file)
(deleted),
patch
|
fitzgen
:
review+
|
Details | Diff | Splinter Review |
No description provided.
Assignee | ||
Comment 1•9 years ago
|
||
Attachment #8718076 -
Flags: review?(jwalden+bmo)
Assignee | ||
Comment 2•9 years ago
|
||
Assignee: nobody → nfitzgerald
Status: NEW → ASSIGNED
Comment 3•9 years ago
|
||
Comment on attachment 8718076 [details] [diff] [review]
Add a `reverse` method to `mozilla::Vector`
Review of attachment 8718076 [details] [diff] [review]:
-----------------------------------------------------------------
::: mfbt/Vector.h
@@ +517,5 @@
> ConstRange all() const { return ConstRange(begin(), end()); }
>
> /* mutators */
>
> + void reverse() {
Add
MOZ_REENTRANCY_GUARD_ET_AL;
since as documented earlier none of these methods are reentrant.
And given that, we can slightly optimize this to avoid massive over-repetition of begin() here.
@@ +521,5 @@
> + void reverse() {
> + for (size_t i = 0; i < length() / 2; i++) {
> + T temp(Move(begin()[i]));
> + begin()[i] = Move(begin()[length() - i - 1]);
> + begin()[length() - i - 1] = Move(temp);
How about using mozilla::Swap instead of the manual local temp?
So then you'd have
T* elems = begin();
size_t len = length();
for (size_t i = 0, mid = len / 2; i < mid; i++) {
Swap(elems[i], elems[len - i - 1]);
}
::: mfbt/tests/TestVector.cpp
@@ +167,5 @@
>
> +void
> +mozilla::detail::VectorTesting::testReverse()
> +{
> + Vector<UniquePtr<uint8_t>> vec;
Just for general sanity, could you test this on a Vector storing elements only in reserved space, and on a Vector storing elements in allocated space? Also test an empty array and an array with an even number of elements, to test the floordiv in the implementation doesn't have off-by-one issues.
Attachment #8718076 -
Flags: review?(jwalden+bmo) → review+
Assignee | ||
Comment 4•9 years ago
|
||
Attachment #8718374 -
Flags: review+
Assignee | ||
Updated•9 years ago
|
Attachment #8718076 -
Attachment is obsolete: true
Assignee | ||
Comment 5•9 years ago
|
||
Assignee | ||
Updated•9 years ago
|
Keywords: checkin-needed
Keywords: checkin-needed
Comment 7•9 years ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
status-firefox47:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla47
You need to log in
before you can comment on or make changes to this bug.
Description
•