Skip to content

Commit 1c7a71b

Browse files
committed
---
yaml --- r: 231813 b: refs/heads/auto c: 714f2a8 h: refs/heads/master i: 231811: 4fe052b v: v3
1 parent 6b99efb commit 1c7a71b

File tree

4 files changed

+58
-38
lines changed

4 files changed

+58
-38
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503
88
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
99
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1010
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
11-
refs/heads/auto: 4f5267dba31fdc49e436c50009fe33a80f21d477
11+
refs/heads/auto: 714f2a8921b1e686ae2ba02965fcd3b3e733e4c3
1212
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1313
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336
1414
refs/tags/0.2: 1754d02027f2924bed83b0160ee340c7f41d5ea1

branches/auto/src/librustc/util/nodemap.rs

Lines changed: 2 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -13,54 +13,19 @@
1313
#![allow(non_snake_case)]
1414

1515
use middle::def_id::DefId;
16-
use std::collections::hash_state::DefaultState;
17-
use std::collections::{HashMap, HashSet};
18-
use std::default::Default;
19-
use std::hash::{Hasher, Hash};
2016
use syntax::ast;
2117

22-
pub type FnvHashMap<K, V> = HashMap<K, V, DefaultState<FnvHasher>>;
23-
pub type FnvHashSet<V> = HashSet<V, DefaultState<FnvHasher>>;
18+
pub use rustc_data_structures::fnv::FnvHashMap;
19+
pub use rustc_data_structures::fnv::FnvHashSet;
2420

2521
pub type NodeMap<T> = FnvHashMap<ast::NodeId, T>;
2622
pub type DefIdMap<T> = FnvHashMap<DefId, T>;
2723

2824
pub type NodeSet = FnvHashSet<ast::NodeId>;
2925
pub type DefIdSet = FnvHashSet<DefId>;
3026

31-
pub fn FnvHashMap<K: Hash + Eq, V>() -> FnvHashMap<K, V> {
32-
Default::default()
33-
}
34-
pub fn FnvHashSet<V: Hash + Eq>() -> FnvHashSet<V> {
35-
Default::default()
36-
}
37-
3827
pub fn NodeMap<T>() -> NodeMap<T> { FnvHashMap() }
3928
pub fn DefIdMap<T>() -> DefIdMap<T> { FnvHashMap() }
4029
pub fn NodeSet() -> NodeSet { FnvHashSet() }
4130
pub fn DefIdSet() -> DefIdSet { FnvHashSet() }
4231

43-
/// A speedy hash algorithm for node ids and def ids. The hashmap in
44-
/// libcollections by default uses SipHash which isn't quite as speedy as we
45-
/// want. In the compiler we're not really worried about DOS attempts, so we
46-
/// just default to a non-cryptographic hash.
47-
///
48-
/// This uses FNV hashing, as described here:
49-
/// http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
50-
pub struct FnvHasher(u64);
51-
52-
impl Default for FnvHasher {
53-
fn default() -> FnvHasher { FnvHasher(0xcbf29ce484222325) }
54-
}
55-
56-
impl Hasher for FnvHasher {
57-
fn write(&mut self, bytes: &[u8]) {
58-
let FnvHasher(mut hash) = *self;
59-
for byte in bytes {
60-
hash = hash ^ (*byte as u64);
61-
hash = hash.wrapping_mul(0x100000001b3);
62-
}
63-
*self = FnvHasher(hash);
64-
}
65-
fn finish(&self) -> u64 { self.0 }
66-
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
use std::collections::{HashMap, HashSet};
12+
use std::collections::hash_state::DefaultState;
13+
use std::default::Default;
14+
use std::hash::{Hasher, Hash};
15+
16+
pub type FnvHashMap<K, V> = HashMap<K, V, DefaultState<FnvHasher>>;
17+
pub type FnvHashSet<V> = HashSet<V, DefaultState<FnvHasher>>;
18+
19+
#[allow(non_snake_case)]
20+
pub fn FnvHashMap<K: Hash + Eq, V>() -> FnvHashMap<K, V> {
21+
Default::default()
22+
}
23+
24+
#[allow(non_snake_case)]
25+
pub fn FnvHashSet<V: Hash + Eq>() -> FnvHashSet<V> {
26+
Default::default()
27+
}
28+
29+
/// A speedy hash algorithm for node ids and def ids. The hashmap in
30+
/// libcollections by default uses SipHash which isn't quite as speedy as we
31+
/// want. In the compiler we're not really worried about DOS attempts, so we
32+
/// just default to a non-cryptographic hash.
33+
///
34+
/// This uses FNV hashing, as described here:
35+
/// http://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function
36+
pub struct FnvHasher(u64);
37+
38+
impl Default for FnvHasher {
39+
fn default() -> FnvHasher { FnvHasher(0xcbf29ce484222325) }
40+
}
41+
42+
impl Hasher for FnvHasher {
43+
fn write(&mut self, bytes: &[u8]) {
44+
let FnvHasher(mut hash) = *self;
45+
for byte in bytes {
46+
hash = hash ^ (*byte as u64);
47+
hash = hash.wrapping_mul(0x100000001b3);
48+
}
49+
*self = FnvHasher(hash);
50+
}
51+
fn finish(&self) -> u64 { self.0 }
52+
}

branches/auto/src/librustc_data_structures/lib.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
html_root_url = "https://doc.rust-lang.org/nightly/")]
2929

3030
#![feature(rustc_private, staged_api)]
31+
#![feature(hashmap_hasher)]
32+
3133
#![cfg_attr(test, feature(test))]
3234

3335
#[macro_use] extern crate log;
@@ -39,6 +41,7 @@ pub mod ivar;
3941
pub mod snapshot_vec;
4042
pub mod transitive_relation;
4143
pub mod unify;
44+
pub mod fnv;
4245

4346
// See comments in src/librustc/lib.rs
4447
#[doc(hidden)]

0 commit comments

Comments
 (0)