Skip to content

Commit

Permalink
Run rustfmt on selectors, servo_arc, and style.
Browse files Browse the repository at this point in the history
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 c99bcdd
Show file tree
Hide file tree
Showing 181 changed files with 9,983 additions and 7,935 deletions.
79 changes: 42 additions & 37 deletions components/selectors/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
}
}
Expand All @@ -41,7 +39,7 @@ pub enum ParsedAttrSelectorOperation<AttrValue> {
operator: AttrSelectorOperator,
case_sensitivity: ParsedCaseSensitivity,
expected_value: AttrValue,
}
},
}

#[derive(Clone, Eq, PartialEq)]
Expand All @@ -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,
),
}
}
}
Expand All @@ -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 {
Expand All @@ -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))
},
}
}
}
Expand All @@ -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,
}
Expand Down Expand Up @@ -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
}
}
},
}
}
}
68 changes: 42 additions & 26 deletions components/selectors/bloom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand All @@ -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;
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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));
}
}
Expand Down Expand Up @@ -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()));
}
});
Expand All @@ -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()));
}
});
}

Expand All @@ -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()));
}
});
}

Expand All @@ -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())
}
});
}
}
Loading

0 comments on commit c99bcdd

Please sign in to comment.