Closed Bug 1278754 Opened 9 years ago Closed 9 years ago

add Vector::initLengthUninitialized

Categories

(Core :: MFBT, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED
mozilla50
Tracking Status
firefox50 --- fixed

People

(Reporter: luke, Assigned: luke)

References

Details

Attachments

(1 file, 1 obsolete file)

Attached patch add-init-length (obsolete) — Splinter Review
This patch introduces a new method initLengthUninitialized() which is equivalent to, but nicer to read than: initCapacity(length) infallibleGrowByUninitialized(length) In particular, this is useful for Vectors that are grown once to a target size and thus do not need the over-allocation that resize() provides. Using this method instead of plain resize() saves 10mb on the wasm Unity demo.
Attachment #8761063 - Flags: review?(jwalden+bmo)
Attached patch add-init-lengthSplinter Review
Oops, curlies.
Attachment #8761063 - Attachment is obsolete: true
Attachment #8761063 - Flags: review?(jwalden+bmo)
Attachment #8761064 - Flags: review?(jwalden+bmo)
Blocks: 1276028
Comment on attachment 8761064 [details] [diff] [review] add-init-length Review of attachment 8761064 [details] [diff] [review]: ----------------------------------------------------------------- Possibly worth adding docs along the lines of, "If you don't subsequently initialize the elements you've allocated before the vector is destroyed, behavior is undefined." or somesuch. ::: mfbt/Vector.h @@ +981,5 @@ > +Vector<T, N, AP>::initLengthUninitialized(size_t aRequest) > +{ > + if (!initCapacity(aRequest)) { > + return false; > + } Bah, braces. So stoopid.
Attachment #8761064 - Flags: review?(jwalden+bmo) → review+
Well, technically I think it's totally well-defined if you're destroying POD types (and non-virtual classes with trivial or boring destructors etc etc), so I don't think I need to sound quite that scary. And it's not just destruction either; there's also resize (copy) etc. I'll update the first sentence to be more clear that its totally uninitialized memory (with all the caveats that comes with), though.
Status: ASSIGNED → RESOLVED
Closed: 9 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla50
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: