Closed
Bug 1278754
Opened 9 years ago
Closed 9 years ago
add Vector::initLengthUninitialized
Categories
(Core :: MFBT, defect)
Core
MFBT
Tracking
()
RESOLVED
FIXED
mozilla50
| Tracking | Status | |
|---|---|---|
| firefox50 | --- | fixed |
People
(Reporter: luke, Assigned: luke)
References
Details
Attachments
(1 file, 1 obsolete file)
|
1.88 KB,
patch
|
Waldo
:
review+
|
Details | Diff | 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)
| Assignee | ||
Comment 1•9 years ago
|
||
Oops, curlies.
Attachment #8761063 -
Attachment is obsolete: true
Attachment #8761063 -
Flags: review?(jwalden+bmo)
Attachment #8761064 -
Flags: review?(jwalden+bmo)
Comment 2•9 years ago
|
||
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+
| Assignee | ||
Comment 3•9 years ago
|
||
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.
| Assignee | ||
Comment 4•9 years ago
|
||
Comment 5•9 years ago
|
||
https://hg.mozilla.org/mozilla-central/rev/03765412b2a8 - landed this morning.
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.
Description
•