diff options
author | bors-servo <lbergstrom+bors@mozilla.com> | 2016-07-21 03:05:56 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-07-21 03:05:56 -0500 |
commit | 4a77cbdbb2fc1a4f163171356a7f5340e1237317 (patch) | |
tree | 5b33ff4e743ab70dafb1b2a15115434ec3bfa8e7 /components/script/dom/window.rs | |
parent | 20b1764d71a967ee4a355cd1b55e4250fe5f59a9 (diff) | |
parent | 73d7db0d5eda75bdbf38f55ed9b40405cb2fd364 (diff) | |
download | servo-4a77cbdbb2fc1a4f163171356a7f5340e1237317.tar.gz servo-4a77cbdbb2fc1a4f163171356a7f5340e1237317.zip |
Auto merge of #12521 - Manishearth:safer-coord, r=bholley
Introduce safer layer of sugar for nsStyleUnion
This routes (almost) all access to nsStyleUnion through a largely safe interface, CoordData.
It also introduces a corresponding Rust enum, CoordDataValue, which can be used when interacting with CoordData
LLVM should optimize the costs away in release mode. eddyb tested this a bit, and LLVM has no trouble threading matches together with inlining -- so all of the matches using enums here will have the same generated code as the old matches on the units.
Some unresolved questions:
Should I provide convenience methods like `set_coord`, `set_auto`, etc on CoordData? `.set_enum(CoordDataValue::Something)` should optimize down to the same thing, but the convenience methods look cleaner and won't load the optimizer as much.
Also, we're converting immutable references to mutable ones, which can be used to cause unsafety using some acrobatics. Perhaps a trait-based approach is better?
The issue is that in some places we only have a `&CoordData` (eg copy_from), but CoordData internally is `*mut`. It would be nice if CoordData could parametrize over its mutability, but Rust doesn't let us do that.
The alternate approach is to make CoordData a trait (also CoordDataMut). The trait requires you to implement `get_union()` and `get_unit()`, and gives you the rest of the functions for free. `nsStyleCoord` would directly implement both traits. `nsStyleSides` would have `data_at(idx)` and `data_at_mut(idx)` methods which return a struct `SidesData` containing a reference to the Sides and the index, which itself implements the `CoordData` and `CoordDataMut` trait (we need two traits here because there will have to be two `SidesData` structs).
I decided not to implement the traits approach first since it's pretty trivial to change this code to use traits, and the current design is more straightforward.
Thoughts?
r? @bholley
cc @emilio @heycam
<!-- 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/12521)
<!-- Reviewable:end -->
Diffstat (limited to 'components/script/dom/window.rs')
0 files changed, 0 insertions, 0 deletions