Closed Bug 1081606 Opened 9 years ago Closed 9 years ago

Don't call toArray with a zero-length array.

Categories

(Firefox for Android Graveyard :: General, defect)

ARM
Android
defect
Not set
normal

Tracking

(Not tracked)

RESOLVED FIXED
Firefox 35

People

(Reporter: ckitching, Assigned: ckitching)

Details

Attachments

(1 file)

Collections provide a toArray method which spits out an array of the same type as the one you pass it.
If the array you pass it is large enough to hold the contents of the collection, your output goes in there. If not, the library uses Reflection to create a new array of the required type and size, and returns that.

This is, unsurprisingly, painfully slow. You can always create an array of precisely the right size using Collection.size(), so just do that.

(If you're thinking that doing this on a LinkedList is not okay because size() is linear... it's not. The LinkedList implementation keeps a "size" variable internally and keeps count as you add/remove elements, so it's constant-time to do size()).
Comment on attachment 8503710 [details] [diff] [review]
Don't call toArray with zero-size arrays

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

Yay perf.

Upstream needed.
Attachment #8503710 - Flags: review?(rnewman) → review+
https://hg.mozilla.org/mozilla-central/rev/8bb3624363e5
Status: NEW → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 35
Product: Firefox for Android → Firefox for Android Graveyard
You need to log in before you can comment on or make changes to this bug.