Skip to content

Commit 7b02f29

Browse files
committed
Switch lint over to using a smallintmap.
1 parent 3dfb174 commit 7b02f29

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

src/rustc/middle/lint.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import syntax::{ast, visit};
44
import syntax::attr;
55
import syntax::codemap::span;
66
import std::map::{map,hashmap,int_hash,hash_from_strs};
7+
import std::smallintmap::{map,smallintmap};
78
import io::writer_util;
89
import syntax::print::pprust::expr_to_str;
910

@@ -29,6 +30,18 @@ enum lint {
2930
old_vecs,
3031
}
3132

33+
// This is pretty unfortunate. We really want some sort of "deriving Enum"
34+
// type of thing.
35+
fn int_to_lint(i: int) -> lint {
36+
alt check i {
37+
0 { ctypes }
38+
1 { unused_imports }
39+
2 { while_true }
40+
3 { path_statement }
41+
4 { old_vecs }
42+
}
43+
}
44+
3245
enum level {
3346
ignore, warn, error
3447
}
@@ -75,22 +88,22 @@ fn get_lint_dict() -> lint_dict {
7588
}
7689

7790
type ctxt = @{dict: lint_dict,
78-
curr: hashmap<lint, level>,
91+
curr: smallintmap<level>,
7992
tcx: ty::ctxt};
8093

8194
impl methods for ctxt {
8295
fn get_level(lint: lint) -> level {
83-
alt self.curr.find(lint) {
96+
alt self.curr.find(lint as uint) {
8497
some(c) { c }
8598
none { ignore }
8699
}
87100
}
88101

89102
fn set_level(lint: lint, level: level) {
90103
if level == ignore {
91-
self.curr.remove(lint);
104+
self.curr.remove(lint as uint);
92105
} else {
93-
self.curr.insert(lint, level);
106+
self.curr.insert(lint as uint, level);
94107
}
95108
}
96109

@@ -186,7 +199,7 @@ fn time(do_it: bool, what: str, thunk: fn()) {
186199
fn check_item(cx: ctxt, i: @ast::item) {
187200
cx.with_warn_attrs(i.attrs) {|cx|
188201
for cx.curr.each {|lint, level|
189-
alt lint {
202+
alt int_to_lint(lint as int) {
190203
ctypes { check_item_ctypes(cx, level, i); }
191204
unused_imports { check_item_unused_imports(cx, level, i); }
192205
while_true { check_item_while_true(cx, level, i); }
@@ -338,7 +351,7 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate,
338351
fn eq_lint(&&a: lint, &&b: lint) -> bool { a == b }
339352

340353
let cx = @{dict: get_lint_dict(),
341-
curr: hashmap(hash_lint, eq_lint),
354+
curr: std::smallintmap::mk(),
342355
tcx: tcx};
343356

344357
// Install defaults.

0 commit comments

Comments
 (0)