diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2017-05-19 18:37:14 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-05-19 18:37:14 -0500 |
commit | 60682cf81fe19a82c73dd98ba4c1eebc1dbbfcac (patch) | |
tree | 9004384638efc214b00b9024c26cfa454e764c46 /components/script/dom/bindings/codegen/parser/tests/test_arraybuffer.py | |
parent | d1e31f7aa46b3b230194de805fff38afcaf9eb68 (diff) | |
parent | 341fc54313aa35980119868cb90854a91c1c6e63 (diff) | |
download | servo-60682cf81fe19a82c73dd98ba4c1eebc1dbbfcac.tar.gz servo-60682cf81fe19a82c73dd98ba4c1eebc1dbbfcac.zip |
Auto merge of #16954 - servo:arrayvec, r=emilio
Avoid returning / passing around a huge ParsedDeclaration type
This enum type used to contain the result of parsing one CSS source declaration (`name: value;`) and expanding shorthands. Enum types are as big as the biggest of their variant (plus discriminant), which was quite big because some shorthands expand to many longhand properties. This type was returned through many functions and methods, wrapped and rewrapped in `Result` with different error types. This presumably caused significant `memmove` traffic.
Instead, we now allocate an `ArrayVec` on the stack and pass `&mut` references to it for various functions to push into it. This type is also very big, but we never move it.
We still use an intermediate data structure because we sometimes decide after shorthand expansion that a declaration is invalid after all and that we’re gonna drop it. Only later do we push to a `PropertyDeclarationBlock`, with an entire `ArrayVec` or nothing.
In future work we can try to avoid a large stack-allocated array, and instead writing directly to the heap allocation of the `Vec` inside `PropertyDeclarationBlock`. However this is tricky: we need to preserve this "all or nothing" aspect of parsing one source declaration, and at the same time we want to make it as little error-prone as possible for the various call sites. `PropertyDeclarationBlock` curently does property deduplication incrementally: as each `PropertyDeclaration` is pushed, we check if an existing declaration of the same property exists and if so overwrite it. To get rid of the stack allocated array we’d need to somehow deduplicate separately after pushing multiple `PropertyDeclaration`.
<!-- Reviewable:start -->
---
This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/16954)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/bindings/codegen/parser/tests/test_arraybuffer.py')
0 files changed, 0 insertions, 0 deletions