Add ability to nsCOMArray to preallocate space

RESOLVED FIXED

Status

()

RESOLVED FIXED
13 years ago
13 years ago

People

(Reporter: sicking, Assigned: sicking)

Tracking

Trunk
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment, 2 obsolete attachments)

It'd be nice to have the ability in nsCOMArray to allocate space for a set number of objects. This is useful when inserting a known number of objects since it allows both less error checking and fewer allocations.

Patch comming up.
Created attachment 211957 [details] [diff] [review]
Implement EnsureStorageFor

Not sure if the name is great. Other suggestions welcome. 

I should add that I'm going to add code that uses this function soon, so it's not dead code.
Attachment #211957 - Flags: superreview?(darin)
Attachment #211957 - Flags: review?(darin)

Comment 2

13 years ago
Comment on attachment 211957 [details] [diff] [review]
Implement EnsureStorageFor

I think this should be called SetCapacity to be more consistent with other container classes (e.g., nsString and nsTArray).
Created attachment 212024 [details] [diff] [review]
Better name
Attachment #211957 - Attachment is obsolete: true
Attachment #212024 - Flags: superreview?(darin)
Attachment #212024 - Flags: review?(darin)
Attachment #211957 - Flags: superreview?(darin)
Attachment #211957 - Flags: review?(darin)
Comment on attachment 212024 [details] [diff] [review]
Better name

Hmm.. looking at strings i'm not sure if the name is ideal as the function is implemented.

nsTSubstring::SetCapacity currently sets the capacity to
NS_MIN(mLength, aSize)
whereas this code sets it to
mLength + aSize

New patch coming up.
Attachment #212024 - Attachment is obsolete: true
Attachment #212024 - Flags: superreview?(darin)
Attachment #212024 - Flags: review?(darin)
Created attachment 212151 [details] [diff] [review]
patch v2

So nsTSubstring::SetCapacity and nsTArray::SetCapacity behave differently. The nsTSubstring one will reduce the length of the string if it can't fit in the new capacity, nsTArray will simply never make the capacity smaller then mLength.

I made nsCOMArray behave like nsTArray
Attachment #212151 - Flags: superreview?(darin)
Attachment #212151 - Flags: review?(darin)

Updated

13 years ago
Attachment #212151 - Flags: superreview?(darin)
Attachment #212151 - Flags: superreview+
Attachment #212151 - Flags: review?(darin)
Attachment #212151 - Flags: review+
It'd be nice to have this on the 1.8 and 1.8.0 branches for bug 271669.

Comment 7

13 years ago
Comment on attachment 212151 [details] [diff] [review]
patch v2

a=darin for 1.8.1
Attachment #212151 - Flags: approval-branch-1.8.1+
I just landed this on MOZILLA_1_8_BRANCH and (without approval) MOZILLA_1_8_0_BRANCH so that I could land bug 271669.
This was checked in some time ago
Status: NEW → RESOLVED
Last Resolved: 13 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.