mirror of
https://github.com/servo/servo.git
synced 2025-08-11 00:15:32 +01:00
Auto merge of #15953 - bholley:size_of_stylo, r=Manishearth
Make size_of tests measure stylo and reduce the size of stylo PropertyDeclarations by 16 bytes Right now they don't, which means that we have four properties making PropertyDeclaration 16 bytes bigger than it should be. I'm not sure if there's a better way to get these tests to run against stylo than to hoist them into the properties file, but I couldn't figure it out. This seems good enough. <!-- 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/15953) <!-- Reviewable:end -->
This commit is contained in:
commit
f5c67fda04
10 changed files with 81 additions and 51 deletions
|
@ -2,51 +2,12 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use std::mem::size_of;
|
||||
use style::properties::{PropertyDeclaration, specified_value_sizes};
|
||||
|
||||
#[test]
|
||||
fn size_of_property_declaration() {
|
||||
let old = 48;
|
||||
let new = size_of::<PropertyDeclaration>();
|
||||
if new < old {
|
||||
panic!("Your changes have decreased the stack size of PropertyDeclaration enum from {} to {}. \
|
||||
Good work! Please update the size in tests/unit/style/size_of.rs.",
|
||||
old, new)
|
||||
} else if new > old {
|
||||
panic!("Your changes have increased the stack size of PropertyDeclaration enum from {} to {}. \
|
||||
These enum is present in large quantities in the style, and increasing the size \
|
||||
may dramatically affect our memory footprint. Please consider using `boxed=\"True\"` in \
|
||||
the longhand If you feel that the increase is necessary, update to the new size in \
|
||||
tests/unit/style/size_of.rs.",
|
||||
old, new)
|
||||
}
|
||||
::style::properties::test_size_of_property_declaration();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn size_of_specified_values() {
|
||||
let threshold = 40;
|
||||
let longhands = specified_value_sizes();
|
||||
|
||||
let mut failing_messages = vec![];
|
||||
|
||||
for specified_value in longhands {
|
||||
if specified_value.1 >= threshold && !specified_value.2 {
|
||||
failing_messages.push(
|
||||
format!("Your changes have increased the size of {} SpecifiedValue to {}. The threshold is \
|
||||
currently {}. SpecifiedValues are affect size of PropertyDeclaration enum and \
|
||||
increasing the size may dramatically affect our memory footprint. Please consider \
|
||||
using `boxed=\"True\"` in this longhand.",
|
||||
specified_value.0, specified_value.1, threshold));
|
||||
} else if specified_value.1 < threshold && specified_value.2 {
|
||||
failing_messages.push(
|
||||
format!("Your changes have decreased the size of {} SpecifiedValue to {}. Good work! \
|
||||
The threshold is currently {}. Please consider removing `boxed=\"True\"` from this longhand.",
|
||||
specified_value.0, specified_value.1, threshold));
|
||||
}
|
||||
}
|
||||
|
||||
if !failing_messages.is_empty() {
|
||||
panic!("{}", failing_messages.join("\n\n"));
|
||||
}
|
||||
::style::properties::test_size_of_specified_values();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,9 @@ name = "stylo_tests"
|
|||
path = "lib.rs"
|
||||
doctest = false
|
||||
|
||||
[features]
|
||||
testing = ["style/testing"]
|
||||
|
||||
[dependencies]
|
||||
app_units = "0.4"
|
||||
atomic_refcell = "0.1"
|
||||
|
|
|
@ -19,6 +19,7 @@ extern crate servo_url;
|
|||
extern crate style_traits;
|
||||
|
||||
mod sanity_checks;
|
||||
mod size_of;
|
||||
|
||||
#[path = "../../../ports/geckolib/stylesheet_loader.rs"]
|
||||
mod stylesheet_loader;
|
||||
|
|
13
tests/unit/stylo/size_of.rs
Normal file
13
tests/unit/stylo/size_of.rs
Normal file
|
@ -0,0 +1,13 @@
|
|||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#[test]
|
||||
fn size_of_property_declaration() {
|
||||
::style::properties::test_size_of_property_declaration();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn size_of_specified_values() {
|
||||
::style::properties::test_size_of_specified_values();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue