Skip to content

Commit afa046a

Browse files
committed
rustc: Use linked lists instead of hash tables for region binding scopes
Hash tables are overkill.
1 parent 4571175 commit afa046a

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

src/rustc/middle/region.rs

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ import middle::ty;
88
import syntax::{ast, visit};
99
import util::common::new_def_hash;
1010

11+
import std::list;
12+
import std::list::list;
1113
import std::map;
1214
import std::map::hashmap;
1315

@@ -19,6 +21,12 @@ enum parent {
1921
pa_crate
2022
}
2123

24+
/* Records the binding site of a region name. */
25+
type binding = {
26+
name: str,
27+
id: ast::def_id
28+
};
29+
2230
type region_map = {
2331
/*
2432
* Mapping from blocks and function expression to their parent block or
@@ -37,7 +45,7 @@ type ctxt = {
3745
sess: session,
3846
def_map: resolve::def_map,
3947
region_map: @region_map,
40-
names_in_scope: hashmap<str,ast::def_id>,
48+
mut bindings: @list<binding>,
4149

4250
/*
4351
* A list of local IDs that will be parented to the next block we
@@ -106,12 +114,14 @@ fn resolve_ty(ty: @ast::ty, cx: ctxt, visitor: visit::vt<ctxt>) {
106114
ast::re_named(ident) {
107115
// If at item scope, introduce or reuse a binding. If at
108116
// block scope, require that the binding be introduced.
109-
alt cx.names_in_scope.find(ident) {
110-
some(def_id) { region = ty::re_named(def_id); }
117+
let bindings = cx.bindings;
118+
alt list::find(*bindings, {|b| ident == b.name}) {
119+
some(binding) { region = ty::re_named(binding.id); }
111120
none {
112121
let def_id = {crate: ast::local_crate,
113122
node: region_id};
114-
cx.names_in_scope.insert(ident, def_id);
123+
let binding = {name: ident, id: def_id};
124+
cx.bindings = @list::cons(binding, cx.bindings);
115125
region = ty::re_named(def_id);
116126

117127
alt cx.parent {
@@ -248,7 +258,7 @@ fn resolve_expr(expr: @ast::expr, cx: ctxt, visitor: visit::vt<ctxt>) {
248258

249259
fn resolve_item(item: @ast::item, cx: ctxt, visitor: visit::vt<ctxt>) {
250260
// Items create a new outer block scope as far as we're concerned.
251-
let new_cx: ctxt = {names_in_scope: map::new_str_hash(),
261+
let new_cx: ctxt = {bindings: @list::nil,
252262
parent: pa_item(item.id),
253263
in_alt: false
254264
with cx};
@@ -263,7 +273,7 @@ fn resolve_crate(sess: session, def_map: resolve::def_map, crate: @ast::crate)
263273
ast_type_to_region: map::new_int_hash(),
264274
local_blocks: map::new_int_hash(),
265275
region_name_to_fn: new_def_hash()},
266-
names_in_scope: map::new_str_hash(),
276+
mut bindings: @list::nil,
267277
mut queued_locals: [],
268278
parent: pa_crate,
269279
in_alt: false};

0 commit comments

Comments
 (0)