提交 c245d9e9 编写于 作者: P Patrick Walton

Revert "stdlib: Stop incurring vtable dispatch costs when hashmaps are used"

This reverts commit f0250a23.
上级 f0250a23
......@@ -16,7 +16,6 @@
import std::json;
import result;
import std::map;
import std::map::hashmap;
import std::os;
import std::run;
import str;
......
......@@ -5,7 +5,6 @@
import io;
import io::{reader_util, writer_util};
import map;
import map::hashmap;
export json;
export error;
......@@ -37,7 +36,7 @@ enum json {
/* Variant: list */
list([json]),
/* Variant: dict */
dict(map::hashmap<str,json>),
dict(map::map<str,json>),
/* Variant: null */
null,
}
......
......@@ -4,10 +4,6 @@
A map type
*/
import chained::hashmap;
export hashmap, hashfn, eqfn, set, map, chained, mk_hashmap, new_str_hash;
export new_bytes_hash, new_int_hash, new_uint_hash, set_add;
/* Section: Types */
/*
......@@ -27,13 +23,14 @@
type eqfn<K> = fn@(K, K) -> bool;
/*
Type: set
Type: hashset
A convenience type to treat a hashmap as a set
A convenience type to treat a map as a set
*/
type set<K> = hashmap<K, ()>;
type set<K> = map<K, ()>;
type hashmap<K, V> = chained::t<K, V>;
// Temporary alias to make migration easier
type hashmap<K, V> = map<K, V>;
/*
IFace: map
......@@ -106,7 +103,8 @@
}
// FIXME: package this up and export it as a datatype usable for
// external code that doesn't want to pay the cost of a box.
// external code that doesn't want to pay the cost of a box and vtable
// lookups.
mod chained {
type entry<K, V> = {
hash: uint,
......@@ -120,8 +118,8 @@ enum chain<K, V> {
absent
}
type t<K, V> = @{
mutable count: uint,
type t<K, V> = {
mutable size: uint,
mutable chains: [mutable chain<K,V>],
hasher: hashfn<K>,
eqer: eqfn<K>
......@@ -187,7 +185,7 @@ fn insert<K: copy, V: copy>(tbl: t<K,V>, k: K, v: V) -> bool {
let hash = tbl.hasher(k);
alt search_tbl(tbl, k, hash) {
not_found {
tbl.count += 1u;
tbl.size += 1u;
let idx = hash % vec::len(tbl.chains);
let old_chain = tbl.chains[idx];
tbl.chains[idx] = present(@{
......@@ -231,13 +229,13 @@ fn remove<K: copy, V: copy>(tbl: t<K,V>, k: K) -> core::option<V> {
}
found_first(idx, entry) {
tbl.count -= 1u;
tbl.size -= 1u;
tbl.chains[idx] = entry.next;
ret core::option::some(entry.value);
}
found_after(eprev, entry) {
tbl.count -= 1u;
tbl.size -= 1u;
eprev.next = entry.next;
ret core::option::some(entry.value);
}
......@@ -293,12 +291,12 @@ fn items<K: copy, V: copy>(tbl: t<K,V>, blk: fn(K,V)) {
}
}
impl hashmap<K: copy, V: copy> of map<K, V> for t<K, V> {
fn size() -> uint { self.count }
impl <K: copy, V: copy> of map<K, V> for t<K, V> {
fn size() -> uint { self.size }
fn insert(k: K, v: V) -> bool {
let nchains = vec::len(self.chains);
let load = {num: (self.count + 1u) as int, den: nchains as int};
let load = {num: (self.size + 1u) as int, den: nchains as int};
// Structural consts would be nice. This is a const 3/4
// load factor that we compare against.
if !util::rational_leq(load, {num:3, den:4}) { rehash(self); }
......@@ -320,13 +318,13 @@ fn keys(blk: fn(K)) { items(self) { |k, _v| blk(k) } }
fn values(blk: fn(V)) { items(self) { |_k, v| blk(v) } }
}
fn mk<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) -> t<K,V> {
fn mk<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) -> map<K,V> {
let initial_capacity: uint = 32u; // 2^5
let slf: t<K, V> = @{mutable count: 0u,
mutable chains: chains(initial_capacity),
hasher: hasher,
eqer: eqer};
slf
let slf: t<K, V> = {mutable size: 0u,
mutable chains: chains(initial_capacity),
hasher: hasher,
eqer: eqer};
slf as map::<K, V>
}
}
......@@ -341,7 +339,7 @@ fn mk<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>) -> t<K,V> {
eqer - The equality function for key type K
*/
fn mk_hashmap<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>)
-> hashmap<K, V> {
-> map<K, V> {
chained::mk(hasher, eqer)
}
......@@ -350,7 +348,7 @@ fn mk_hashmap<K: copy, V: copy>(hasher: hashfn<K>, eqer: eqfn<K>)
Construct a hashmap for string keys
*/
fn new_str_hash<V: copy>() -> hashmap<str, V> {
fn new_str_hash<V: copy>() -> map<str, V> {
ret mk_hashmap(str::hash, str::eq);
}
......@@ -359,7 +357,7 @@ fn new_str_hash<V: copy>() -> hashmap<str, V> {
Construct a hashmap for byte string keys
*/
fn new_bytes_hash<V: copy>() -> hashmap<[u8], V> {
fn new_bytes_hash<V: copy>() -> map<[u8], V> {
ret mk_hashmap(vec::u8::hash, vec::u8::eq);
}
......@@ -368,7 +366,7 @@ fn new_bytes_hash<V: copy>() -> hashmap<[u8], V> {
Construct a hashmap for int keys
*/
fn new_int_hash<V: copy>() -> hashmap<int, V> {
fn new_int_hash<V: copy>() -> map<int, V> {
fn hash_int(&&x: int) -> uint { int::hash(x) }
fn eq_int(&&a: int, &&b: int) -> bool { ret a == b; }
ret mk_hashmap(hash_int, eq_int);
......@@ -379,7 +377,7 @@ fn hash_int(&&x: int) -> uint { int::hash(x) }
Construct a hashmap for uint keys
*/
fn new_uint_hash<V: copy>() -> hashmap<uint, V> {
fn new_uint_hash<V: copy>() -> map<uint, V> {
fn hash_uint(&&x: uint) -> uint { uint::hash(x) }
fn eq_uint(&&a: uint, &&b: uint) -> bool { ret a == b; }
ret mk_hashmap(hash_uint, eq_uint);
......
import map::hashmap;
export loop_new, loop_delete, run, close, run_in_bg;
export async_init, async_send;
export timer_init, timer_start, timer_stop;
......@@ -130,17 +129,17 @@ fn loop_new() -> uv_loop unsafe {
process_operation);
// all state goes here
let handles: map::hashmap<[u8], *ctypes::void> =
let handles: map::map<[u8], *ctypes::void> =
map::new_bytes_hash();
let id_to_handle: map::hashmap<[u8], uv_handle> =
let id_to_handle: map::map<[u8], uv_handle> =
map::new_bytes_hash();
let after_cbs: map::hashmap<[u8], fn~(uv_handle)> =
let after_cbs: map::map<[u8], fn~(uv_handle)> =
map::new_bytes_hash();
let close_callbacks: map::hashmap<[u8], fn~()> =
let close_callbacks: map::map<[u8], fn~()> =
map::new_bytes_hash();
let async_cbs: map::hashmap<[u8], fn~(uv_handle)> =
let async_cbs: map::map<[u8], fn~(uv_handle)> =
map::new_bytes_hash();
let timer_cbs: map::hashmap<[u8], fn~(uv_handle)> =
let timer_cbs: map::map<[u8], fn~(uv_handle)> =
map::new_bytes_hash();
// the main loop that this task blocks on.
......
......@@ -7,7 +7,6 @@
import metadata::{encoder, cstore};
import middle::trans::common::crate_ctxt;
import std::fs;
import std::map::hashmap;
import std::run;
import std::sha1::sha1;
import syntax::ast;
......
import std::{os, fs, os_fs, map};
import std::map::hashmap;
import metadata::cstore;
import driver::session;
import util::filesearch;
......
// Functions dealing with attributes and meta_items
import std::map;
import std::map::hashmap;
import syntax::{ast, ast_util};
import driver::session::session;
......
import str::sbuf;
import std::map::hashmap;
import ctypes::{c_int, c_uint, unsigned, longlong, ulonglong};
......
......@@ -4,15 +4,15 @@
import syntax::ast_util;
import syntax::ast_util::inlined_item_methods;
import syntax::codemap::span;
import std::map::map;
import std::smallintmap::map;
import std::ebml;
import std::ebml::writer;
import std::map::hashmap;
import std::serialization;
import std::serialization::serializer;
import std::serialization::deserializer;
import std::serialization::serializer_helpers;
import std::serialization::deserializer_helpers;
import std::smallintmap::map;
import middle::trans::common::maps;
import middle::{ty, typeck, last_use, ast_map};
import middle::typeck::method_origin;
......@@ -922,4 +922,4 @@ fn foo(x: uint, y: uint) -> uint {
ret z;
}
});
}
}
\ No newline at end of file
......@@ -6,7 +6,6 @@
import option::{some, none};
import driver::session;
import middle::trans::common::maps;
import std::map::hashmap;
export get_symbol;
export get_type_param_count;
......
......@@ -2,7 +2,6 @@
// crates and libraries
import std::map;
import std::map::hashmap;
import syntax::ast;
import util::common::*;
......
// Decoding metadata from a single crate's metadata
import std::{ebml, map, io};
import std::map::hashmap;
import io::writer_util;
import syntax::{ast, ast_util};
import driver::session::session;
......
// Metadata encoding
import std::{io, ebml, map, list};
import std::map::hashmap;
import io::writer_util;
import ebml::writer;
import syntax::ast::*;
......
......@@ -10,11 +10,10 @@
import syntax::visit;
import syntax::ast_util::def_id_of_def;
import front::attr;
import std::map::hashmap;
export map, find_reachable;
type map = std::map::hashmap<node_id, ()>;
type map = std::map::map<node_id, ()>;
type ctx = {ccx: middle::trans::common::crate_ctxt,
rmap: map};
......
......@@ -5,7 +5,6 @@
import syntax::ast_util;
import syntax::ast_util::respan;
import middle::ty;
import std::map::hashmap;
export parse_ty_data, parse_def_id;
export parse_bounds_data;
......
......@@ -5,7 +5,6 @@
import syntax::visit;
import visit::vt;
import std::list;
import std::map::hashmap;
import std::util::unreachable;
import option::is_none;
import list::list;
......
import std::map;
import std::map::hashmap;
import syntax::ast::*;
import syntax::ast_util;
import syntax::ast_util::inlined_item_methods;
......@@ -36,7 +35,7 @@ enum ast_node {
node_res_ctor(@item),
}
type map = std::map::hashmap<node_id, ast_node>;
type map = std::map::map<node_id, ast_node>;
type ctx = {map: map, mutable path: path, mutable local_id: uint};
type vt = visit::vt<ctx>;
......
import syntax::{ast, ast_util};
import driver::session::session;
import std::map;
import std::map::hashmap;
export capture_mode;
export capture_var;
......
......@@ -8,7 +8,6 @@
import driver::session::session;
import middle::ty;
import middle::ty::*;
import std::map::hashmap;
fn check_crate(tcx: ty::ctxt, crate: @crate) {
visit::visit_crate(*crate, (), visit::mk_vt(@{
......
import syntax::ast::*;
import syntax::{visit, ast_util};
import driver::session::session;
import std::map::hashmap;
fn check_crate(sess: session, crate: @crate, method_map: typeck::method_map) {
visit::visit_crate(*crate, false, visit::mk_vt(@{
......
import std::map::hashmap;
import syntax::ast;
import syntax::visit;
import syntax::print::pprust::expr_to_str;
......
......@@ -3,7 +3,6 @@
import syntax::codemap::span;
import ty::{kind, kind_copyable, kind_sendable, kind_noncopyable};
import driver::session::session;
import std::map::hashmap;
// Kind analysis pass. There are three kinds:
//
......
......@@ -4,7 +4,6 @@
import std::list::{is_not_empty, list, nil, cons, tail};
import std::util::unreachable;
import std::list;
import std::map::hashmap;
// Last use analysis pass.
//
......
......@@ -3,7 +3,6 @@
import syntax::{ast, visit};
import front::attr;
import std::io;
import std::map::hashmap;
import io::writer_util;
enum option {
......
......@@ -2,7 +2,6 @@
import syntax::visit;
import syntax::ast_util;
import driver::session::session;
import std::map::hashmap;
enum deref_t { unbox(bool), field, index, }
......
......@@ -4,7 +4,6 @@
import syntax::fold;
import syntax::fold::*;
import syntax::codemap::span;
import std::map::hashmap;
export walk_pat;
export pat_binding_ids, pat_bindings, pat_id_map;
......
......@@ -12,7 +12,6 @@
import syntax::print::pprust::pat_to_str;
import back::abi;
import resolve::def_map;
import std::map::hashmap;
import common::*;
......
......@@ -18,7 +18,6 @@
import shape::{size_of};
import ast_map::{path, path_mod, path_name};
import driver::session::session;
import std::map::hashmap;
// ___Good to know (tm)__________________________________________________
//
......
......@@ -11,7 +11,6 @@
import lib::llvm::{ValueRef, TypeRef};
import lib::llvm::llvm::LLVMGetParam;
import ast_map::{path, path_mod, path_name};
import std::map::hashmap;
// Translation functionality related to impls and ifaces
//
......
......@@ -9,7 +9,6 @@
import build::*;
import base::*;
import type_of::*;
import std::map::hashmap;
export link_name, trans_native_mod, register_crust_fn, trans_crust_fn;
......@@ -359,4 +358,4 @@ fn register_crust_fn(ccx: crate_ctxt, sp: span,
let llfty = T_fn(llargtys, llretty);
register_fn_fuller(ccx, sp, path, "crust fn", node_id,
t, lib::llvm::CCallConv, llfty)
}
}
\ No newline at end of file
......@@ -3,7 +3,6 @@
import syntax::ast;
import lib::llvm::llvm;
import driver::session::session;
import std::map::hashmap;
import ty::*;
......
......@@ -4,7 +4,7 @@
import syntax::ast_util::*;
import syntax::{visit, codemap};
import codemap::span;
import std::map::{hashmap, new_int_hash};
import std::map::{new_int_hash};
import syntax::print::pprust::path_to_str;
import tstate::ann::{pre_and_post, pre_and_post_state, empty_ann, prestate,
poststate, precond, postcond,
......
......@@ -12,7 +12,6 @@
import tritv::*;
import util::common::*;
import driver::session::session;
import std::map::hashmap;
fn bit_num(fcx: fn_ctxt, c: tsconstr) -> uint {
let d = tsconstr_to_def_id(c);
......
......@@ -14,7 +14,6 @@
import pre_post_conditions::fn_pre_post;
import states::find_pre_post_state_fn;
import driver::session::session;
import std::map::hashmap;
fn check_unused_vars(fcx: fn_ctxt) {
......
......@@ -8,7 +8,6 @@
import syntax::ast_util::respan;
import driver::session::session;
import aux::*;
import std::map::hashmap;
type ctxt = {cs: @mutable [sp_constr], tcx: ty::ctxt};
......
......@@ -13,7 +13,6 @@
has_nonlocal_exits, log_stmt};
import syntax::codemap::span;
import driver::session::session;
import std::map::hashmap;
fn find_pre_post_mod(_m: _mod) -> _mod {
#debug("implement find_pre_post_mod!");
......
......@@ -10,7 +10,6 @@
import middle::ty::{expr_ty, type_is_bot};
import util::common::*;
import driver::session::session;
import std::map::hashmap;
fn forbid_upvar(fcx: fn_ctxt, rhs_id: node_id, sp: span, t: oper_type) {
alt t {
......
......@@ -7,7 +7,6 @@
Rustdoc from its non-sendableness."
)];
import std::map::hashmap;
import rustc::driver::session;
import rustc::driver::driver;
import rustc::driver::diagnostic;
......
......@@ -8,7 +8,6 @@
import rustc::syntax::ast;
import rustc::middle::ast_map;
import std::map::hashmap;
export mk_pass;
......@@ -475,4 +474,4 @@ fn mk_doc(source: str) -> doc::doc {
run(srv, doc)
}
}
}
}
\ No newline at end of file
......@@ -3,7 +3,6 @@
import rustc::syntax::ast;
import rustc::syntax::ast_util;
import rustc::middle::ast_map;
import std::map::hashmap;
export mk_pass;
......@@ -254,4 +253,4 @@ fn mk_doc(source: str) -> doc::doc {
run(srv, doc)
}
}
}
}
\ No newline at end of file
#[doc = "Finds docs for reexported items and duplicates them"];
import std::map;
import std::map::hashmap;
import rustc::syntax::ast;
import rustc::syntax::ast_util;
import rustc::util::common;
......
......@@ -4,7 +4,6 @@
import rustc::syntax::ast;
import rustc::syntax::print::pprust;
import rustc::middle::ast_map;
import std::map::hashmap;
export mk_pass;
......
......@@ -50,7 +50,7 @@ fn parse(argv: [str]) -> parse_result {
type ast_ty = str;
type ast_item = str;
type tp_map = hashmap<ast::node_id, ty::t>;
type tp_map = map<ast::node_id, ty::t>;
type serialize_ctx = {
crate: @ast::crate,
......@@ -519,4 +519,4 @@ fn main(argv: [str]) {
vec::iter(copy sctx.item_fns) {|item|
stdout.write_str(#fmt["%s\n", item])
}
}
}
\ No newline at end of file
......@@ -14,7 +14,6 @@
use std;
import std::io::writer_util;
import std::map::hashmap;
type cmplx = {re: f64, im: f64};
type line = {i: uint, b: [u8]};
......
......@@ -13,7 +13,6 @@
import option = option;
import option::{some, none};
import std::{map, io, time};
import std::map::hashmap;
import io::reader_util;
import comm::chan;
......
use std;
import std::map;
import std::map::hashmap;
import std::map::map;
// Test that iface types printed in error msgs include the type arguments.
fn main() {
let x: map<str,str> = map::new_str_hash::<str>() as map::<str,str>;
let y: map<uint,str> = x;
let x: map<uint,str> = map::new_str_hash::<str>();
//!^ ERROR mismatched types: expected `std::map::map<uint,str>`
}
}
\ No newline at end of file
......@@ -2,7 +2,6 @@
use std;
import std::map;
import std::map::hashmap;
import uint;
fn main() {
......@@ -22,4 +21,4 @@ fn eq(&&s: [@str], &&t: [@str]) -> bool {
map.insert(arr, arr + [@"value stuff"]);
}
map.insert([@"boom"], []);
}
}
\ No newline at end of file
......@@ -12,7 +12,6 @@
import str;
import vec;
import std::map;
import std::map::hashmap;
import task;
import comm::chan;
import comm::port;
......
use std;
import std::map;
import std::map::hashmap;
fn main() {
let m = map::new_bytes_hash();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册