Auto merge of #18355 - servo:no-fmt, r=emilio

Reduce usage of fmt in serialization and error reporting

`format!` and `write!` create a somewhat-heavyweight `Formatting` struct and use dynamic dispatch to call into impls of `Dispaly` and related traits. The former also allocates an intermediate string that is sometimes unnecessary.

I started looking into this from https://bugzilla.mozilla.org/show_bug.cgi?id=1355599, but I expect the impact there will be small to insignificant. It might be a slightly less so on parsing (error reporting).

<!-- 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/18355)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2017-09-04 13:14:44 -05:00 committed by GitHub
commit c60dd53210
27 changed files with 328 additions and 365 deletions

View file

@ -22,7 +22,7 @@ impl ParseErrorReporter for ErrorringErrorReporter {
url: &ServoUrl,
location: SourceLocation,
error: ContextualParseError) {
panic!("CSS error: {}\t\n{}:{} {}", url.as_str(), location.line, location.column, error.to_string());
panic!("CSS error: {}\t\n{}:{} {}", url.as_str(), location.line, location.column, error);
}
}

View file

@ -280,7 +280,7 @@ impl ParseErrorReporter for CSSInvalidErrorReporterTest {
url: url.clone(),
line: location.line,
column: location.column,
message: error.to_string()
message: error.to_string(),
}
);
}

View file

@ -11,7 +11,7 @@ use servo_config::prefs::{PREFS, PrefValue};
use servo_url::ServoUrl;
use style::context::QuirksMode;
use style::media_queries::{Device, MediaList, MediaType};
use style::parser::{Parse, ParserContext, ParserErrorContext};
use style::parser::{ParserContext, ParserErrorContext};
use style::shared_lock::SharedRwLock;
use style::stylesheets::{CssRuleType, Stylesheet, StylesheetInDocument, Origin};
use style::stylesheets::viewport_rule::*;

View file

@ -12,7 +12,6 @@ extern crate selectors;
#[macro_use] extern crate style;
extern crate style_traits;
mod sanity_checks;
#[cfg(target_pointer_width = "64")]
mod size_of;
mod specified_values;

View file

@ -1,28 +0,0 @@
/* 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/. */
//! Different static asserts that ensure the build does what it's expected to.
//!
//! TODO: maybe cfg(test) this?
#![allow(unused_imports)]
use std::mem;
macro_rules! check_enum_value {
($a:expr, $b:expr) => {
unsafe {
mem::transmute::<[u32; $a as usize],
[u32; $b as usize]>([0; $a as usize]);
}
}
}
// NB: It's a shame we can't do this statically with bitflags, but no
// const-fn and no other way to access the numerical value :-(
macro_rules! check_enum_value_non_static {
($a:expr, $b:expr) => {
assert_eq!($a.0 as usize, $b as usize);
}
}

View file

@ -5,6 +5,7 @@
use style;
#[cfg(all(test, target_pointer_width = "64"))]
#[test]
fn size_of_specified_values() {
use std::mem::size_of;
let threshold = 24;

View file

@ -26530,7 +26530,7 @@
"testharness"
],
"mozilla/calc.html": [
"5b3ea33205a9f2404bd6976a2c7f6fc451be8e96",
"4f65929cacf623da2d3e310a6663d6165a1b0cdc",
"testharness"
],
"mozilla/canvas.initial.reset.2dstate.html": [

View file

@ -42,7 +42,7 @@ var widthTests = [
['calc(10px + 10em - 10px)', 'calc(10em + 0px)', '160px'],
// Fold absolute units
['calc(1px + 1pt + 1pc + 1in + 1cm + 1mm)', 'calc(155.91666666666666px)', '155.91666666666666px'],
['calc(96px + 72pt + 6pc + 1in + 2.54cm + 25.4mm)', 'calc(576px)', '576px'],
// Alphabetical order
['calc(0ch + 0px + 0pt + 0pc + 0in + 0cm + 0mm + 0rem + 0em + 0ex + 0% + 0vw + 0vh + 0vmin + 0vmax)',