Use FxHash{Map,Set} instead of the default Hash{Map,Set} everywhere in rustc.

This commit is contained in:
Eduard-Mihai Burtescu 2018-08-18 13:55:43 +03:00
parent 83ddc33347
commit 93f3f5b155
34 changed files with 156 additions and 152 deletions

View file

@ -29,8 +29,9 @@
#![allow(non_camel_case_types)]
use rustc_data_structures::fx::FxHashMap;
use std::cell::RefCell;
use std::collections::{HashMap, VecDeque};
use std::collections::VecDeque;
use std::default::Default;
use std::fmt::{self, Write};
use std::borrow::Cow;
@ -417,14 +418,14 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for SummaryLine<'a, I> {
/// references.
struct Footnotes<'a, I: Iterator<Item = Event<'a>>> {
inner: I,
footnotes: HashMap<String, (Vec<Event<'a>>, u16)>,
footnotes: FxHashMap<String, (Vec<Event<'a>>, u16)>,
}
impl<'a, I: Iterator<Item = Event<'a>>> Footnotes<'a, I> {
fn new(iter: I) -> Self {
Footnotes {
inner: iter,
footnotes: HashMap::new(),
footnotes: FxHashMap::default(),
}
}
fn get_entry(&mut self, key: &str) -> &mut (Vec<Event<'a>>, u16) {
@ -865,7 +866,7 @@ pub fn markdown_links(md: &str) -> Vec<(String, Option<Range<usize>>)> {
#[derive(Default)]
pub struct IdMap {
map: HashMap<String, usize>,
map: FxHashMap<String, usize>,
}
impl IdMap {
@ -880,7 +881,7 @@ impl IdMap {
}
pub fn reset(&mut self) {
self.map = HashMap::new();
self.map = FxHashMap::default();
}
pub fn derive(&mut self, candidate: String) -> String {

View file

@ -38,7 +38,7 @@ pub use self::ExternalLocation::*;
use std::borrow::Cow;
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::{BTreeMap, HashSet, VecDeque};
use std::collections::{BTreeMap, VecDeque};
use std::default::Default;
use std::error;
use std::fmt::{self, Display, Formatter, Write as FmtWrite};
@ -741,7 +741,7 @@ fn write_shared(cx: &Context,
// To avoid "light.css" to be overwritten, we'll first run over the received themes and only
// then we'll run over the "official" styles.
let mut themes: HashSet<String> = HashSet::new();
let mut themes: FxHashSet<String> = FxHashSet::default();
for entry in &cx.shared.themes {
let mut content = Vec::with_capacity(100000);
@ -1539,35 +1539,36 @@ impl Ord for ItemEntry {
#[derive(Debug)]
struct AllTypes {
structs: HashSet<ItemEntry>,
enums: HashSet<ItemEntry>,
unions: HashSet<ItemEntry>,
primitives: HashSet<ItemEntry>,
traits: HashSet<ItemEntry>,
macros: HashSet<ItemEntry>,
functions: HashSet<ItemEntry>,
typedefs: HashSet<ItemEntry>,
existentials: HashSet<ItemEntry>,
statics: HashSet<ItemEntry>,
constants: HashSet<ItemEntry>,
keywords: HashSet<ItemEntry>,
structs: FxHashSet<ItemEntry>,
enums: FxHashSet<ItemEntry>,
unions: FxHashSet<ItemEntry>,
primitives: FxHashSet<ItemEntry>,
traits: FxHashSet<ItemEntry>,
macros: FxHashSet<ItemEntry>,
functions: FxHashSet<ItemEntry>,
typedefs: FxHashSet<ItemEntry>,
existentials: FxHashSet<ItemEntry>,
statics: FxHashSet<ItemEntry>,
constants: FxHashSet<ItemEntry>,
keywords: FxHashSet<ItemEntry>,
}
impl AllTypes {
fn new() -> AllTypes {
let new_set = |cap| FxHashSet::with_capacity_and_hasher(cap, Default::default());
AllTypes {
structs: HashSet::with_capacity(100),
enums: HashSet::with_capacity(100),
unions: HashSet::with_capacity(100),
primitives: HashSet::with_capacity(26),
traits: HashSet::with_capacity(100),
macros: HashSet::with_capacity(100),
functions: HashSet::with_capacity(100),
typedefs: HashSet::with_capacity(100),
existentials: HashSet::with_capacity(100),
statics: HashSet::with_capacity(100),
constants: HashSet::with_capacity(100),
keywords: HashSet::with_capacity(100),
structs: new_set(100),
enums: new_set(100),
unions: new_set(100),
primitives: new_set(26),
traits: new_set(100),
macros: new_set(100),
functions: new_set(100),
typedefs: new_set(100),
existentials: new_set(100),
statics: new_set(100),
constants: new_set(100),
keywords: new_set(100),
}
}
@ -1595,7 +1596,7 @@ impl AllTypes {
}
}
fn print_entries(f: &mut fmt::Formatter, e: &HashSet<ItemEntry>, title: &str,
fn print_entries(f: &mut fmt::Formatter, e: &FxHashSet<ItemEntry>, title: &str,
class: &str) -> fmt::Result {
if !e.is_empty() {
let mut e: Vec<&ItemEntry> = e.iter().collect();
@ -4185,7 +4186,7 @@ fn sidebar_assoc_items(it: &clean::Item) -> String {
}
}
let format_impls = |impls: Vec<&Impl>| {
let mut links = HashSet::new();
let mut links = FxHashSet::default();
impls.iter()
.filter_map(|i| {
let is_negative_impl = is_negative_impl(i.inner_impl());

View file

@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use std::collections::HashSet;
use rustc_data_structures::fx::FxHashSet;
use std::fs::File;
use std::hash::{Hash, Hasher};
use std::io::Read;
@ -31,7 +31,7 @@ macro_rules! try_something {
#[derive(Debug, Clone, Eq)]
pub struct CssPath {
pub name: String,
pub children: HashSet<CssPath>,
pub children: FxHashSet<CssPath>,
}
// This PartialEq implementation IS NOT COMMUTATIVE!!!
@ -66,7 +66,7 @@ impl CssPath {
fn new(name: String) -> CssPath {
CssPath {
name,
children: HashSet::new(),
children: FxHashSet::default(),
}
}
}
@ -211,7 +211,7 @@ fn build_rule(v: &[u8], positions: &[usize]) -> String {
.join(" ")
}
fn inner(v: &[u8], events: &[Events], pos: &mut usize) -> HashSet<CssPath> {
fn inner(v: &[u8], events: &[Events], pos: &mut usize) -> FxHashSet<CssPath> {
let mut paths = Vec::with_capacity(50);
while *pos < events.len() {