Closed Bug 972167 Opened 11 years ago Closed 11 years ago

when copy constructing an nsAutoTArray it does not use its in-built buffer

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla30

People

(Reporter: heycam, Assigned: neil)

References

Details

Attachments

(1 file, 1 obsolete file)

(Found in bug 972078.) I find when I copy construct an nsAutoTArray from another nsAutoTArray that it does not end up invoking either of nsAutoBaseBase's two constructors, and thus doesn't call Init(). This means that mCapacity remains at 0 instead of the fixed internal buffer size, and will mean that the AppendElements call will always allocate memory even if there was enough space in the internal buffer.
Attached patch patch (obsolete) — Splinter Review
Don't really know if this is the right thing, or why the existing explicit copy constructor on nsAutoTArray doesn't get called. But it does fix the problem I was having.
Assignee: nobody → cam
Status: NEW → ASSIGNED
Attachment #8375295 - Flags: review?(benjamin)
Blocks: 972078
Attached patch Proposed patchSplinter Review
I don't think it's the right thing. Comments in nsTArray.h correctly point out that nsTAutoArray's implicit copy constructor will use nsAutoArrayBase's copy constructor. Unfortunately the provided constructor is not a copy constructor because its argument is of the wrong type and so it doesn't get used. How your patch worked was that it was an explicit constructor, so it can only use an explicit superclass constructor, in this case the default constructor, although you should have constructed Base explicitly using explicit nsAutoTArray(const nsAutoTArray<E, N>& other) : Base(other) {}
Assignee: cam → neil
Attachment #8375295 - Attachment is obsolete: true
Attachment #8375295 - Flags: review?(benjamin)
Attachment #8375438 - Flags: review?(benjamin)
Attachment #8375438 - Flags: review?(benjamin) → review?(nfroyd)
Attachment #8375438 - Flags: review?(nfroyd) → review+
https://hg.mozilla.org/integration/mozilla-inbound/rev/c4393e9e9e21 Because the constructor was itself broken, although MSVC doesn't care.
Thanks for finding the correct fix Neil.
Status: ASSIGNED → RESOLVED
Closed: 11 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla30
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: