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

RESOLVED FIXED in Firefox 35

Status

()

defect
RESOLVED FIXED
5 years ago
5 years ago

People

(Reporter: ckitching, Assigned: ckitching)

Tracking

unspecified
Firefox 35
ARM
Android
Points:
---

Firefox Tracking Flags

(Not tracked)

Details

Attachments

(1 attachment)

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: 5 years ago
Resolution: --- → FIXED
Target Milestone: --- → Firefox 35
You need to log in before you can comment on or make changes to this bug.