Skip to content
Permalink
Browse files

Run rustfmt on selectors, servo_arc, and style.

This was generated with:

./mach cargo fmt --package selectors &&
./mach cargo fmt --package servo_arc &&
./mach cargo fmt --package style

Using rustfmt 0.4.1-nightly (a4462d1 2018-03-26)
  • Loading branch information
bholley committed Apr 11, 2018
1 parent f7ae1a3 commit c99bcdd4b8d4b4ac495d8a26eb8a4d2c710a2589
Showing with 9,983 additions and 7,935 deletions.
  1. +42 −37 components/selectors/attr.rs
  2. +42 −26 components/selectors/bloom.rs
  3. +33 −40 components/selectors/builder.rs
  4. +7 −16 components/selectors/context.rs
  5. +9 −5 components/selectors/lib.rs
  6. +210 −251 components/selectors/matching.rs
  7. +1 −5 components/selectors/nth_index_cache.rs
  8. +858 −570 components/selectors/parser.rs
  9. +1 −1 components/selectors/tree.rs
  10. +1 −3 components/selectors/visitor.rs
  11. +65 −38 components/servo_arc/lib.rs
  12. +182 −135 components/style/animation.rs
  13. +6 −9 components/style/applicable_declarations.rs
  14. +74 −58 components/style/attr.rs
  15. +5 −13 components/style/author_styles.rs
  16. +5 −6 components/style/bezier.rs
  17. +25 −20 components/style/bloom.rs
  18. +35 −12 components/style/build.rs
  19. +133 −74 components/style/build_gecko.rs
  20. +94 −44 components/style/context.rs
  21. +105 −63 components/style/counter_style/mod.rs
  22. +131 −97 components/style/custom_properties.rs
  23. +63 −44 components/style/data.rs
  24. +76 −60 components/style/dom.rs
  25. +48 −87 components/style/dom_apis.rs
  26. +33 −30 components/style/driver.rs
  27. +54 −42 components/style/encoding_support.rs
  28. +98 −59 components/style/error_reporting.rs
  29. +58 −36 components/style/font_face.rs
  30. +11 −3 components/style/font_metrics.rs
  31. +4 −5 components/style/gecko/arc_types.rs
  32. +289 −239 components/style/gecko/conversions.rs
  33. +18 −19 components/style/gecko/data.rs
  34. +135 −113 components/style/gecko/media_queries.rs
  35. +9 −4 components/style/gecko/pseudo_element.rs
  36. +1 −2 components/style/gecko/restyle_damage.rs
  37. +27 −18 components/style/gecko/rules.rs
  38. +65 −41 components/style/gecko/selector_parser.rs
  39. +22 −22 components/style/gecko/snapshot.rs
  40. +7 −11 components/style/gecko/snapshot_helpers.rs
  41. +14 −12 components/style/gecko/traversal.rs
  42. +25 −15 components/style/gecko/url.rs
  43. +107 −78 components/style/gecko/values.rs
  44. +275 −273 components/style/gecko/wrapper.rs
  45. +2 −1 components/style/gecko_bindings/mod.rs
  46. +8 −4 components/style/gecko_bindings/sugar/ns_css_shadow_array.rs
  47. +1 −1 components/style/gecko_bindings/sugar/ns_css_shadow_item.rs
  48. +56 −36 components/style/gecko_bindings/sugar/ns_css_value.rs
  49. +9 −3 components/style/gecko_bindings/sugar/ns_style_auto_array.rs
  50. +38 −58 components/style/gecko_bindings/sugar/ns_style_coord.rs
  51. +18 −16 components/style/gecko_bindings/sugar/ns_t_array.rs
  52. +58 −40 components/style/gecko_bindings/sugar/ns_timing_function.rs
  53. +16 −15 components/style/gecko_bindings/sugar/ownership.rs
  54. +49 −29 components/style/gecko_bindings/sugar/refptr.rs
  55. +49 −47 components/style/gecko_string_cache/mod.rs
  56. +7 −6 components/style/gecko_string_cache/namespace.rs
  57. +0 −1 components/style/hash.rs
  58. +6 −6 components/style/invalidation/element/document_state.rs
  59. +31 −38 components/style/invalidation/element/element_wrapper.rs
  60. +38 −31 components/style/invalidation/element/invalidation_map.rs
  61. +115 −136 components/style/invalidation/element/invalidator.rs
  62. +16 −13 components/style/invalidation/element/restyle_hints.rs
  63. +72 −85 components/style/invalidation/element/state_and_attributes.rs
  64. +12 −19 components/style/invalidation/media_queries.rs
  65. +84 −63 components/style/invalidation/stylesheets.rs
  66. +71 −31 components/style/lib.rs
  67. +234 −93 components/style/logical_geometry.rs
  68. +13 −10 components/style/macros.rs
  69. +101 −82 components/style/matching.rs
  70. +43 −27 components/style/media_queries.rs
  71. +39 −40 components/style/parallel.rs
  72. +19 −12 components/style/parser.rs
  73. +13 −9 components/style/rule_cache.rs
  74. +224 −165 components/style/rule_tree/mod.rs
  75. +49 −49 components/style/selector_map.rs
  76. +10 −11 components/style/selector_parser.rs
  77. +21 −18 components/style/servo/media_queries.rs
  78. +93 −51 components/style/servo/restyle_damage.rs
  79. +63 −41 components/style/servo/selector_parser.rs
  80. +11 −7 components/style/servo/url.rs
  81. +20 −25 components/style/shared_lock.rs
  82. +9 −17 components/style/sharing/checks.rs
  83. +84 −49 components/style/sharing/mod.rs
  84. +48 −43 components/style/str.rs
  85. +119 −103 components/style/style_adjuster.rs
  86. +90 −92 components/style/style_resolver.rs
  87. +25 −18 components/style/stylesheet_set.rs
  88. +42 −28 components/style/stylesheets/document_rule.rs
  89. +59 −23 components/style/stylesheets/font_feature_values_rule.rs
  90. +3 −6 components/style/stylesheets/import_rule.rs
  91. +115 −74 components/style/stylesheets/keyframes_rule.rs
  92. +3 −1 components/style/stylesheets/media_rule.rs
  93. +66 −43 components/style/stylesheets/mod.rs
  94. +14 −8 components/style/stylesheets/origin.rs
  95. +33 −33 components/style/stylesheets/rule_list.rs
  96. +98 −81 components/style/stylesheets/rule_parser.rs
  97. +66 −73 components/style/stylesheets/rules_iterator.rs
  98. +1 −2 components/style/stylesheets/style_rule.rs
  99. +41 −57 components/style/stylesheets/stylesheet.rs
  100. +48 −41 components/style/stylesheets/supports_rule.rs
  101. +156 −130 components/style/stylesheets/viewport_rule.rs
  102. +260 −318 components/style/stylist.rs
  103. +4 −4 components/style/timer.rs
  104. +197 −165 components/style/traversal.rs
  105. +39 −19 components/style/values/animated/color.rs
  106. +13 −23 components/style/values/animated/effects.rs
  107. +23 −13 components/style/values/animated/mod.rs
  108. +14 −12 components/style/values/computed/align.rs
  109. +4 −7 components/style/values/computed/angle.rs
  110. +24 −19 components/style/values/computed/background.rs
  111. +3 −2 components/style/values/computed/basic_shape.rs
  112. +8 −2 components/style/values/computed/border.rs
  113. +1 −1 components/style/values/computed/box.rs
  114. +5 −7 components/style/values/computed/color.rs
  115. +51 −39 components/style/values/computed/counters.rs
  116. +97 −72 components/style/values/computed/font.rs
  117. +29 −51 components/style/values/computed/image.rs
  118. +149 −173 components/style/values/computed/length.rs
  119. +12 −10 components/style/values/computed/list.rs
  120. +69 −41 components/style/values/computed/mod.rs
  121. +3 −3 components/style/values/computed/percentage.rs
  122. +8 −8 components/style/values/computed/pointing.rs
  123. +8 −6 components/style/values/computed/svg.rs
  124. +7 −5 components/style/values/computed/text.rs
  125. +1 −3 components/style/values/computed/time.rs
  126. +96 −55 components/style/values/computed/transform.rs
  127. +2 −2 components/style/values/computed/url.rs
  128. +12 −5 components/style/values/distance.rs
  129. +3 −3 components/style/values/generics/background.rs
  130. +44 −30 components/style/values/generics/basic_shape.rs
  131. +18 −12 components/style/values/generics/border.rs
  132. +4 −4 components/style/values/generics/box.rs
  133. +2 −2 components/style/values/generics/column.rs
  134. +1 −1 components/style/values/generics/counters.rs
  135. +7 −10 components/style/values/generics/effects.rs
  136. +2 −2 components/style/values/generics/flex.rs
  137. +9 −7 components/style/values/generics/font.rs
  138. +1 −1 components/style/values/generics/gecko.rs
  139. +57 −46 components/style/values/generics/grid.rs
  140. +25 −16 components/style/values/generics/image.rs
  141. +15 −12 components/style/values/generics/mod.rs
  142. +2 −2 components/style/values/generics/pointing.rs
  143. +4 −4 components/style/values/generics/position.rs
  144. +31 −13 components/style/values/generics/rect.rs
  145. +7 −7 components/style/values/generics/size.rs
  146. +43 −43 components/style/values/generics/svg.rs
  147. +14 −9 components/style/values/generics/text.rs
  148. +42 −74 components/style/values/generics/transform.rs
  149. +6 −3 components/style/values/generics/url.rs
  150. +32 −18 components/style/values/mod.rs
  151. +54 −26 components/style/values/specified/align.rs
  152. +27 −19 components/style/values/specified/angle.rs
  153. +5 −5 components/style/values/specified/background.rs
  154. +90 −46 components/style/values/specified/basic_shape.rs
  155. +25 −8 components/style/values/specified/border.rs
  156. +80 −69 components/style/values/specified/box.rs
  157. +172 −190 components/style/values/specified/calc.rs
  158. +72 −87 components/style/values/specified/color.rs
  159. +4 −1 components/style/values/specified/column.rs
  160. +15 −7 components/style/values/specified/counters.rs
  161. +27 −17 components/style/values/specified/effects.rs
  162. +535 −376 components/style/values/specified/font.rs
  163. +19 −16 components/style/values/specified/gecko.rs
  164. +130 −83 components/style/values/specified/grid.rs
  165. +166 −149 components/style/values/specified/image.rs
  166. +33 −18 components/style/values/specified/inherited_box.rs
  167. +195 −129 components/style/values/specified/length.rs
  168. +17 −12 components/style/values/specified/list.rs
  169. +127 −66 components/style/values/specified/mod.rs
  170. +6 −5 components/style/values/specified/outline.rs
  171. +8 −8 components/style/values/specified/percentage.rs
  172. +68 −45 components/style/values/specified/position.rs
  173. +4 −2 components/style/values/specified/rect.rs
  174. +22 −25 components/style/values/specified/source_size_list.rs
  175. +25 −18 components/style/values/specified/svg.rs
  176. +5 −2 components/style/values/specified/table.rs
  177. +133 −82 components/style/values/specified/text.rs
  178. +27 −17 components/style/values/specified/time.rs
  179. +44 −42 components/style/values/specified/transform.rs
  180. +6 −2 components/style/values/specified/ui.rs
  181. +2 −2 components/style/values/specified/url.rs
@@ -19,9 +19,7 @@ impl<Impl: SelectorImpl> AttrSelectorWithNamespace<Impl> {
pub fn namespace(&self) -> NamespaceConstraint<&Impl::NamespaceUrl> {
match self.namespace {
NamespaceConstraint::Any => NamespaceConstraint::Any,
NamespaceConstraint::Specific((_, ref url)) => {
NamespaceConstraint::Specific(url)
}
NamespaceConstraint::Specific((_, ref url)) => NamespaceConstraint::Specific(url),
}
}
}
@@ -41,7 +39,7 @@ pub enum ParsedAttrSelectorOperation<AttrValue> {
operator: AttrSelectorOperator,
case_sensitivity: ParsedCaseSensitivity,
expected_value: AttrValue,
}
},
}

#[derive(Clone, Eq, PartialEq)]
@@ -51,16 +49,25 @@ pub enum AttrSelectorOperation<AttrValue> {
operator: AttrSelectorOperator,
case_sensitivity: CaseSensitivity,
expected_value: AttrValue,
}
},
}

impl<AttrValue> AttrSelectorOperation<AttrValue> {
pub fn eval_str(&self, element_attr_value: &str) -> bool where AttrValue: AsRef<str> {
pub fn eval_str(&self, element_attr_value: &str) -> bool
where
AttrValue: AsRef<str>,
{
match *self {
AttrSelectorOperation::Exists => true,
AttrSelectorOperation::WithValue { operator, case_sensitivity, ref expected_value } => {
operator.eval_str(element_attr_value, expected_value.as_ref(), case_sensitivity)
}
AttrSelectorOperation::WithValue {
operator,
case_sensitivity,
ref expected_value,
} => operator.eval_str(
element_attr_value,
expected_value.as_ref(),
case_sensitivity,
),
}
}
}
@@ -76,7 +83,10 @@ pub enum AttrSelectorOperator {
}

impl ToCss for AttrSelectorOperator {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result
where
W: fmt::Write,
{
// https://drafts.csswg.org/cssom/#serializing-selectors
// See "attribute selector".
dest.write_str(match *self {
@@ -91,34 +101,30 @@ impl ToCss for AttrSelectorOperator {
}

impl AttrSelectorOperator {
pub fn eval_str(self, element_attr_value: &str, attr_selector_value: &str,
case_sensitivity: CaseSensitivity) -> bool {
pub fn eval_str(
self,
element_attr_value: &str,
attr_selector_value: &str,
case_sensitivity: CaseSensitivity,
) -> bool {
let e = element_attr_value.as_bytes();
let s = attr_selector_value.as_bytes();
let case = case_sensitivity;
match self {
AttrSelectorOperator::Equal => {
case.eq(e, s)
}
AttrSelectorOperator::Prefix => {
e.len() >= s.len() && case.eq(&e[..s.len()], s)
}
AttrSelectorOperator::Equal => case.eq(e, s),
AttrSelectorOperator::Prefix => e.len() >= s.len() && case.eq(&e[..s.len()], s),
AttrSelectorOperator::Suffix => {
e.len() >= s.len() && case.eq(&e[(e.len() - s.len())..], s)
}
},
AttrSelectorOperator::Substring => {
case.contains(element_attr_value, attr_selector_value)
}
AttrSelectorOperator::Includes => {
element_attr_value.split(SELECTOR_WHITESPACE)
.any(|part| case.eq(part.as_bytes(), s))
}
},
AttrSelectorOperator::Includes => element_attr_value
.split(SELECTOR_WHITESPACE)
.any(|part| case.eq(part.as_bytes(), s)),
AttrSelectorOperator::DashMatch => {
case.eq(e, s) || (
e.get(s.len()) == Some(&b'-') &&
case.eq(&e[..s.len()], s)
)
}
case.eq(e, s) || (e.get(s.len()) == Some(&b'-') && case.eq(&e[..s.len()], s))
},
}
}
}
@@ -137,12 +143,13 @@ impl ParsedCaseSensitivity {
pub fn to_unconditional(self, is_html_element_in_html_document: bool) -> CaseSensitivity {
match self {
ParsedCaseSensitivity::AsciiCaseInsensitiveIfInHtmlElementInHtmlDocument
if is_html_element_in_html_document => {
if is_html_element_in_html_document =>
{
CaseSensitivity::AsciiCaseInsensitive
}
},
ParsedCaseSensitivity::AsciiCaseInsensitiveIfInHtmlElementInHtmlDocument => {
CaseSensitivity::CaseSensitive
}
},
ParsedCaseSensitivity::CaseSensitive => CaseSensitivity::CaseSensitive,
ParsedCaseSensitivity::AsciiCaseInsensitive => CaseSensitivity::AsciiCaseInsensitive,
}
@@ -170,22 +177,20 @@ impl CaseSensitivity {
if let Some((&n_first_byte, n_rest)) = needle.as_bytes().split_first() {
haystack.bytes().enumerate().any(|(i, byte)| {
if !byte.eq_ignore_ascii_case(&n_first_byte) {
return false
return false;
}
let after_this_byte = &haystack.as_bytes()[i + 1..];
match after_this_byte.get(..n_rest.len()) {
None => false,
Some(haystack_slice) => {
haystack_slice.eq_ignore_ascii_case(n_rest)
}
Some(haystack_slice) => haystack_slice.eq_ignore_ascii_case(n_rest),
}
})
} else {
// any_str.contains("") == true,
// though these cases should be handled with *NeverMatches and never go here.
true
}
}
},
}
}
}
@@ -72,11 +72,17 @@ pub type NonCountingBloomFilter = CountingBloomFilter<BloomStorageBool>;
/// positive rate for N == 100 and to quite bad false positive
/// rates for larger N.
#[derive(Clone)]
pub struct CountingBloomFilter<S> where S: BloomStorage {
pub struct CountingBloomFilter<S>
where
S: BloomStorage,
{
storage: S,
}

impl<S> CountingBloomFilter<S> where S: BloomStorage {
impl<S> CountingBloomFilter<S>
where
S: BloomStorage,
{
/// Creates a new bloom filter.
#[inline]
pub fn new() -> Self {
@@ -128,8 +134,7 @@ impl<S> CountingBloomFilter<S> where S: BloomStorage {

#[inline]
pub fn might_contain_hash(&self, hash: u32) -> bool {
!self.storage.first_slot_is_empty(hash) &&
!self.storage.second_slot_is_empty(hash)
!self.storage.first_slot_is_empty(hash) && !self.storage.second_slot_is_empty(hash)
}

/// Check whether the filter might contain an item. This can
@@ -142,7 +147,10 @@ impl<S> CountingBloomFilter<S> where S: BloomStorage {
}
}

impl<S> Debug for CountingBloomFilter<S> where S: BloomStorage {
impl<S> Debug for CountingBloomFilter<S>
where
S: BloomStorage,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let mut slots_used = 0;
for i in 0..ARRAY_SIZE {
@@ -154,7 +162,7 @@ impl<S> Debug for CountingBloomFilter<S> where S: BloomStorage {
}
}

pub trait BloomStorage : Clone + Default {
pub trait BloomStorage: Clone + Default {
fn slot_is_empty(&self, index: usize) -> bool;
fn adjust_slot(&mut self, index: usize, increment: bool);
fn is_zeroed(&self) -> bool;
@@ -199,7 +207,8 @@ impl BloomStorage for BloomStorageU8 {
#[inline]
fn adjust_slot(&mut self, index: usize, increment: bool) {
let slot = &mut self.counters[index];
if *slot != 0xff { // full
if *slot != 0xff {
// full
if increment {
*slot += 1;
} else {
@@ -249,8 +258,10 @@ impl BloomStorage for BloomStorageBool {
// Since we have only one bit for storage, decrementing it
// should never do anything. Assert against an accidental
// decrementing of a bit that was never set.
assert!(increment || (*byte & bit) != 0,
"should not decrement if slot is already false");
assert!(
increment || (*byte & bit) != 0,
"should not decrement if slot is already false"
);

if increment {
*byte |= bit;
@@ -314,34 +325,33 @@ fn create_and_insert_some_stuff() {
transmute::<[u8; ARRAY_SIZE % 8], [u8; 0]>([]);
}

for i in 0_usize .. 1000 {
for i in 0_usize..1000 {
bf.insert(&i);
}

for i in 0_usize .. 1000 {
for i in 0_usize..1000 {
assert!(bf.might_contain(&i));
}

let false_positives =
(1001_usize .. 2000).filter(|i| bf.might_contain(i)).count();
let false_positives = (1001_usize..2000).filter(|i| bf.might_contain(i)).count();

assert!(false_positives < 150, "{} is not < 150", false_positives); // 15%.

for i in 0_usize .. 100 {
for i in 0_usize..100 {
bf.remove(&i);
}

for i in 100_usize .. 1000 {
for i in 100_usize..1000 {
assert!(bf.might_contain(&i));
}

let false_positives = (0_usize .. 100).filter(|i| bf.might_contain(i)).count();
let false_positives = (0_usize..100).filter(|i| bf.might_contain(i)).count();

assert!(false_positives < 20, "{} is not < 20", false_positives); // 20%.

bf.clear();

for i in 0_usize .. 2000 {
for i in 0_usize..2000 {
assert!(!bf.might_contain(&i));
}
}
@@ -376,13 +386,13 @@ mod bench {
let mut gen1 = HashGenerator::default();
let mut gen2 = HashGenerator::default();
let mut bf = BloomFilter::new();
for _ in 0_usize .. 1000 {
for _ in 0_usize..1000 {
bf.insert_hash(gen1.next());
}
for _ in 0_usize .. 100 {
for _ in 0_usize..100 {
bf.remove_hash(gen2.next());
}
for _ in 100_usize .. 200 {
for _ in 100_usize..200 {
test::black_box(bf.might_contain_hash(gen2.next()));
}
});
@@ -392,8 +402,10 @@ mod bench {
fn might_contain_10(b: &mut test::Bencher) {
let bf = BloomFilter::new();
let mut gen = HashGenerator::default();
b.iter(|| for _ in 0..10 {
test::black_box(bf.might_contain_hash(gen.next()));
b.iter(|| {
for _ in 0..10 {
test::black_box(bf.might_contain_hash(gen.next()));
}
});
}

@@ -407,8 +419,10 @@ mod bench {
fn insert_10(b: &mut test::Bencher) {
let mut bf = BloomFilter::new();
let mut gen = HashGenerator::default();
b.iter(|| for _ in 0..10 {
test::black_box(bf.insert_hash(gen.next()));
b.iter(|| {
for _ in 0..10 {
test::black_box(bf.insert_hash(gen.next()));
}
});
}

@@ -417,8 +431,10 @@ mod bench {
let mut bf = BloomFilter::new();
let mut gen = HashGenerator::default();
// Note: this will underflow, and that's ok.
b.iter(|| for _ in 0..10 {
bf.remove_hash(gen.next())
b.iter(|| {
for _ in 0..10 {
bf.remove_hash(gen.next())
}
});
}
}

0 comments on commit c99bcdd

Please sign in to comment.
You can’t perform that action at this time.