Skip to content

Commit

Permalink
Tidy fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Manishearth committed Sep 1, 2017
1 parent ce4e1e4 commit 3ddb1fd
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 22 deletions.
2 changes: 1 addition & 1 deletion components/hashglobe/Cargo.toml
Expand Up @@ -14,4 +14,4 @@ libc = "0.2"
heapsize = "0.4"

[dev-dependencies]
rand = "0.3"
rand = "0.3"
39 changes: 24 additions & 15 deletions components/hashglobe/src/fake.rs
@@ -1,16 +1,25 @@
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

//! This module contains shims around the stdlib HashMap
//! that add fallible methods
//!
//! These methods are a lie. They are not actually fallible. This is just to make
//! it smooth to switch between hashmap impls in a codebase.

use std::hash::{BuildHasher, Hash};
use heapsize::HeapSizeOf;
use std::collections::HashMap as StdMap;
use std::collections::HashSet as StdSet;
use std::ops::{Deref, DerefMut};
use std::fmt;

use heapsize::HeapSizeOf;
use std::hash::{BuildHasher, Hash};
use std::ops::{Deref, DerefMut};

pub use std::collections::hash_map::{Entry, RandomState, Iter as MapIter, IterMut as MapIterMut};
pub use std::collections::hash_set::{Iter as SetIter, IntoIter as SetIntoIter};
Expand All @@ -25,17 +34,16 @@ impl<K, V, S> Deref for HashMap<K, V, S> {
type Target = StdMap<K, V, S>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
}

impl<K, V, S> DerefMut for HashMap<K, V, S> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
}

impl<K: Hash + Eq, V> HashMap<K, V, RandomState> {

#[inline]
pub fn new() -> HashMap<K, V, RandomState> {
HashMap(StdMap::new())
Expand Down Expand Up @@ -63,7 +71,9 @@ impl<K, V, S> HashMap<K, V, S>
}

#[inline]
pub fn try_with_capacity_and_hasher(capacity: usize, hash_builder: S) -> Result<HashMap<K, V, S>, FailedAllocationError> {
pub fn try_with_capacity_and_hasher(capacity: usize,
hash_builder: S)
-> Result<HashMap<K, V, S>, FailedAllocationError> {
Ok(HashMap(StdMap::with_capacity_and_hasher(capacity, hash_builder)))
}

Expand Down Expand Up @@ -99,17 +109,16 @@ impl<T, S> Deref for HashSet<T, S> {
type Target = StdSet<T, S>;
fn deref(&self) -> &Self::Target {
&self.0
}
}
}

impl<T, S> DerefMut for HashSet<T, S> {
fn deref_mut(&mut self) -> &mut Self::Target {
&mut self.0
}
}
}

impl<T: Hash + Eq> HashSet<T, RandomState> {

#[inline]
pub fn new() -> HashSet<T, RandomState> {
HashSet(StdSet::new())
Expand All @@ -126,7 +135,6 @@ impl<T, S> HashSet<T, S>
where T: Eq + Hash,
S: BuildHasher
{

#[inline]
pub fn with_hasher(hasher: S) -> HashSet<T, S> {
HashSet(StdSet::with_hasher(hasher))
Expand Down Expand Up @@ -158,10 +166,11 @@ impl<T, S> HashSet<T, S>
// We can't derive these since the bounds are not obvious to the derive macro


impl<K: HeapSizeOf + Hash + Eq, V: HeapSizeOf, S: BuildHasher> HeapSizeOf for HashMap<K, V, S> {
impl<K: HeapSizeOf + Hash + Eq, V: HeapSizeOf, S: BuildHasher>
HeapSizeOf for HashMap<K, V, S> {
fn heap_size_of_children(&self) -> usize {
self.0.heap_size_of_children()
}
}
}

impl<K: Hash + Eq, V, S: BuildHasher + Default> Default for HashMap<K, V, S> {
Expand Down Expand Up @@ -224,7 +233,7 @@ impl<'a, K, V, S> IntoIterator for &'a mut HashMap<K, V, S>
impl<T: HeapSizeOf + Eq + Hash, S: BuildHasher> HeapSizeOf for HashSet<T, S> {
fn heap_size_of_children(&self) -> usize {
self.0.heap_size_of_children()
}
}
}

impl<T: Eq + Hash, S: BuildHasher + Default> Default for HashSet<T, S> {
Expand Down
14 changes: 12 additions & 2 deletions components/hashglobe/src/lib.rs
@@ -1,12 +1,22 @@
// Copyright 2014-2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub use std::*;

extern crate heapsize;

mod table;
mod shim;
mod alloc;
pub mod hash_map;
pub mod hash_set;
mod shim;
mod table;

pub mod fake;

Expand Down
2 changes: 1 addition & 1 deletion components/style/custom_properties.rs
Expand Up @@ -8,13 +8,13 @@

use Atom;
use cssparser::{Delimiter, Parser, ParserInput, SourcePosition, Token, TokenSerializationType};
use hash::{HashMap, HashSet};
use parser::ParserContext;
use properties::{CSSWideKeyword, DeclaredValue};
use selectors::parser::SelectorParseError;
use servo_arc::Arc;
use std::ascii::AsciiExt;
use std::borrow::{Borrow, Cow};
use hash::{HashMap, HashSet};
use std::fmt;
use std::hash::Hash;
use style_traits::{ToCss, StyleParseError, ParseError};
Expand Down
2 changes: 1 addition & 1 deletion components/style/gecko/wrapper.rs
Expand Up @@ -66,6 +66,7 @@ use gecko_bindings::structs::nsChangeHint;
use gecko_bindings::structs::nsIDocument_DocumentTheme as DocumentTheme;
use gecko_bindings::structs::nsRestyleHint;
use gecko_bindings::sugar::ownership::{HasArcFFI, HasSimpleFFI};
use hash::HashMap;
use logical_geometry::WritingMode;
use media_queries::Device;
use properties::{ComputedValues, parse_style_attribute};
Expand All @@ -83,7 +84,6 @@ use selectors::sink::Push;
use servo_arc::{Arc, ArcBorrow, RawOffsetArc};
use shared_lock::Locked;
use std::cell::RefCell;
use hash::HashMap;
use std::fmt;
use std::hash::{Hash, Hasher};
use std::mem;
Expand Down
4 changes: 2 additions & 2 deletions components/style/selector_map.rs
Expand Up @@ -9,15 +9,15 @@ use {Atom, LocalName};
use applicable_declarations::ApplicableDeclarationBlock;
use context::QuirksMode;
use dom::TElement;
use hash::{HashMap, HashSet};
use hash::map as hash_map;
use pdqsort::sort_by;
use precomputed_hash::PrecomputedHash;
use rule_tree::CascadeLevel;
use selector_parser::SelectorImpl;
use selectors::matching::{matches_selector, MatchingContext, ElementSelectorFlags};
use selectors::parser::{Component, Combinator, SelectorIter};
use smallvec::{SmallVec, VecLike};
use hash::{HashMap, HashSet};
use hash::map as hash_map;
use std::hash::{BuildHasherDefault, Hash, Hasher};
use stylist::Rule;

Expand Down
2 changes: 2 additions & 0 deletions servo-tidy.toml
Expand Up @@ -15,6 +15,7 @@ lint-scripts = [
rand = [
"deque",
"gaol",
"hashglobe", # only uses in tests
"ipc-channel",
"num-bigint",
"parking_lot_core",
Expand Down Expand Up @@ -74,6 +75,7 @@ directories = [
"./components/script/dom/bindings/codegen/parser",
"./components/script/dom/bindings/codegen/ply",
"./python/_virtualenv",
"./components/hashglobe/src",
# Generated and upstream code combined with our own. Could use cleanup
"./target",
"./ports/cef",
Expand Down

0 comments on commit 3ddb1fd

Please sign in to comment.