Closed Bug 686597 Opened 13 years ago Closed 13 years ago

nsAutoTArray doesn't have a copy-constructor.

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla9

People

(Reporter: justin.lebar+bug, Assigned: justin.lebar+bug)

References

Details

Attachments

(1 file, 1 obsolete file)

In bug 682735 comment 52, we noticed that nsAutoTArray doesn't have a copy-constructor.  The following code:

  nsAutoTArray<E, 16> foo;
  // put some elements in foo
  nsAutoTArray<E, 16> bar(foo);

effectively makes |bar| a nsTArray; |bar| will never use its auto storage.

We can fix this simply by adding copy constructors.
Assignee: nobody → justin.lebar+bug
Depends on: 677571
Luke pointed out that js vectors don't have copy constructors -- if you want to copy a vector, you need to do so explicitly.

I'm going to see whether we can just do that here.
Well, nsTArray has a copy-constructor, and I'm not sure we're ready to get rid of that.  So maybe nsAutoTArray should also have one.
I need to test that this fixes the issues we saw in bug 682735 comment 52, but unfortunately my instrumentation doesn't work on mac.  I think this should work...
Attachment #560281 - Flags: review?(bzbarsky)
Comment on attachment 560281 [details] [diff] [review]
Add a copy constructor to nsAutoTArray and friends.

>+++ b/xpcom/glue/nsTArray.h
>+  nsAutoArrayBase(const nsAutoArrayBase<TArrayBase, N> &aOther) {

Any reason to not make that argument |const TArrayBase &aOther|?

r=me either way.
Attachment #560281 - Flags: review?(bzbarsky) → review+
(In reply to Boris Zbarsky (:bz) from comment #4)
> >+++ b/xpcom/glue/nsTArray.h
> >+  nsAutoArrayBase(const nsAutoArrayBase<TArrayBase, N> &aOther) {
> 
> Any reason to not make that argument |const TArrayBase &aOther|?

I think just to emphasize that the constructor shouldn't be called except by nsAutoArrayBase's children's copy-constructors.

But in that case, maybe it should be protected...
OS: Mac OS X → Windows Mobile 6 Professional
OS: Windows Mobile 6 Professional → All
Hardware: x86 → All
Attached patch Patch v2Splinter Review
Making the constructors protected.
Attachment #560504 - Flags: review?(bzbarsky)
Attachment #560281 - Attachment is obsolete: true
Comment on attachment 560504 [details] [diff] [review]
Patch v2

r=me
Attachment #560504 - Flags: review?(bzbarsky) → review+
https://hg.mozilla.org/mozilla-central/rev/304a0a282365
Status: NEW → RESOLVED
Closed: 13 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla9
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: