Closed Bug 1185763 Opened 9 years ago Closed 9 years ago

Rename deceptively named nsTArray::MoveElementsFrom

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla45
Tracking Status
firefox42 --- affected
firefox45 --- fixed

People

(Reporter: poiru, Assigned: poiru)

Details

Attachments

(7 files)

As seen in bug 1185759, nsTArray::MoveElementsFrom is not the best name. I think we should rename it to something like AppendRawElements. Nathan, any thoughts?
Flags: needinfo?(nfroyd)
(In reply to Birunthan Mohanathas [:poiru] from comment #0)
> As seen in bug 1185759, nsTArray::MoveElementsFrom is not the best name. I
> think we should rename it to something like AppendRawElements. Nathan, any
> thoughts?

Gah, I meant to say AppendMovedElements. Also, I think we should remove the non-r-value reference version of MoveElementsFrom to make the intent clear.
AppendMovedElements WFM.  Is MoveElementsFrom actually doing C++-level moving currently?
Flags: needinfo?(nfroyd)
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #2)
> AppendMovedElements WFM.  Is MoveElementsFrom actually doing C++-level
> moving currently?

Nope. I decided to go with 'Merge' as I think that describes the intent more clearly.
Assignee: nobody → birunthan
Status: NEW → ASSIGNED
Attachment #8637246 - Flags: review?(nfroyd)
I don't know what the right name is, but I don't think Merge is the right name, as that tends to get used for sorting algorithms...
(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #8)
> I don't know what the right name is, but I don't think Merge is the right
> name, as that tends to get used for sorting algorithms...

How about just AppendArray, then? Together with Part 2, I think that is a sufficiently descriptive name.
(In reply to Birunthan Mohanathas [:poiru] from comment #9)
> (In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #8)
> > I don't know what the right name is, but I don't think Merge is the right
> > name, as that tends to get used for sorting algorithms...
> 
> How about just AppendArray, then? Together with Part 2, I think that is a
> sufficiently descriptive name.

If we're going to do that, why not just add an infallible-only nsTArray&& overload to AppendElements?
Attachment #8637246 - Flags: review?(nfroyd) → review+
Attachment #8637249 - Flags: review?(nfroyd) → review+
Attachment #8637250 - Flags: review?(nfroyd) → review+
Attachment #8637247 - Flags: review?(nfroyd) → review+
Attachment #8637248 - Flags: review?(nfroyd) → review+
Probably easiest to do the renaming as a part 6 followup if we go with AppendElements(nsTArray&&).

Tests would also be appreciated to make sure we get this right.
I modified my local patches to use AppendElements as per comment 11.
Attachment #8638008 - Flags: review?(nfroyd)
Comment on attachment 8638009 [details] [diff] [review]
Part 7: Add test for r-value nsTArray::AppendElements

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

As fine as these tests are, I think it'd be better to have something like:

class MoveChecker
{
public:
  MoveChecker() { sNormalConstructs++; }
  MoveChecker(const MoveChecker&) { ...; sCopyConstructs++; }
  MoveChecker(MoveChecker&&) { ...; sMoveConstructs++; }
  ...
};

etc. similar to what test_move_array in TestTArray.cpp already does (maybe you can even reuse Countable and Movable?).  Then assert that the counts are what you expect after each operation, in addition to asserting properties of the array itself.
Attachment #8638009 - Flags: review?(nfroyd) → feedback+
Comment on attachment 8638008 [details] [diff] [review]
Part 6: Add fallible variant of r-value nsTArray::AppendElements

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

::: xpcom/glue/nsTArray.h
@@ +1542,1 @@
>    elem_type* AppendElements(nsTArray_Impl<Item, Allocator>&& aArray)

I forget; we want to unprotect this eventually, correct?
Attachment #8638008 - Flags: review?(nfroyd) → review+
Comment on attachment 8638009 [details] [diff] [review]
Part 7: Add test for r-value nsTArray::AppendElements

(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #14)
> Comment on attachment 8638009 [details] [diff] [review]
> Part 7: Add test for r-value nsTArray::AppendElements
> 
> Review of attachment 8638009 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> As fine as these tests are, I think it'd be better to have something like:
> 
> class MoveChecker
> {
> public:
>   MoveChecker() { sNormalConstructs++; }
>   MoveChecker(const MoveChecker&) { ...; sCopyConstructs++; }
>   MoveChecker(MoveChecker&&) { ...; sMoveConstructs++; }
>   ...
> };
> 
> etc. similar to what test_move_array in TestTArray.cpp already does (maybe
> you can even reuse Countable and Movable?).  Then assert that the counts are
> what you expect after each operation, in addition to asserting properties of
> the array itself.

With the r-value version of AppendElements, we just steal the bits of the given array rather than invoking the move constructor or move assignment operator. Therefore, I don't think the Moveable class would be appropriate here. I'm rerequesting review in hopes that you agree.

(In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #15)
> Comment on attachment 8638008 [details] [diff] [review]
> Part 6: Add fallible variant of r-value nsTArray::AppendElements
> 
> Review of attachment 8638008 [details] [diff] [review]:
> -----------------------------------------------------------------
> 
> ::: xpcom/glue/nsTArray.h
> @@ +1542,1 @@
> >    elem_type* AppendElements(nsTArray_Impl<Item, Allocator>&& aArray)
> 
> I forget; we want to unprotect this eventually, correct?

Yep, that'll happen after we switch (most) uses of FallibleTArray to nsTArray.
Attachment #8638009 - Flags: review?(nfroyd)
(In reply to Birunthan Mohanathas [:poiru] from comment #16)
> (In reply to Nathan Froyd [:froydnj][:nfroyd] from comment #14)
> > class MoveChecker
> > {
> > public:
> >   MoveChecker() { sNormalConstructs++; }
> >   MoveChecker(const MoveChecker&) { ...; sCopyConstructs++; }
> >   MoveChecker(MoveChecker&&) { ...; sMoveConstructs++; }
> >   ...
> > };
> > 
> > etc. similar to what test_move_array in TestTArray.cpp already does (maybe
> > you can even reuse Countable and Movable?).  Then assert that the counts are
> > what you expect after each operation, in addition to asserting properties of
> > the array itself.
> 
> With the r-value version of AppendElements, we just steal the bits of the
> given array rather than invoking the move constructor or move assignment
> operator. Therefore, I don't think the Moveable class would be appropriate
> here. I'm rerequesting review in hopes that you agree.

I'm assuming that by "steal the bits", you mean "blast them into place with memcpy/memmove", correct?

That doesn't necessarily happen for all types, e.g. http://mxr.mozilla.org/mozilla-central/source/xpcom/glue/nsTArray.h#670

and looking at the code, I don't think we get this right now...
Comment on attachment 8638009 [details] [diff] [review]
Part 7: Add test for r-value nsTArray::AppendElements

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

Actually, let's fix the move issues in another bug.  They are orthogonal to the issues being addressed here.
Attachment #8638009 - Flags: review?(nfroyd) → review+
Apparently I forgot to land the last 2 patches. I'll do that later after a Try push.
Keywords: leave-open
Keywords: leave-open
https://hg.mozilla.org/mozilla-central/rev/499a2fece05b
https://hg.mozilla.org/mozilla-central/rev/dcb8086b1ffa
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla45
removing the b2g 2.5 flag since this commit has been reverted due to an incorrect merge, sorry for the confusion
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: