Closed Bug 327256 Opened 19 years ago Closed 19 years ago

Add ability to nsCOMArray to preallocate space

Categories

(Core :: XPCOM, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: sicking, Assigned: sicking)

References

Details

Attachments

(1 file, 2 obsolete files)

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.
Attached patch Implement EnsureStorageFor (obsolete) — Splinter Review
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 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).
Attached patch Better name (obsolete) — Splinter Review
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)
Attached patch patch v2Splinter Review
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)
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 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
Closed: 19 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: