about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorMichael Sullivan <sully@msully.net>2012-05-31 15:06:45 -0700
committerMichael Sullivan <sully@msully.net>2012-05-31 18:38:42 -0700
commit7b02f29d47a05eb4cc018b362e87f3c05181e4e2 (patch)
tree0e19ffff3bc192e4d5cac1a0c0a8de1edce6f14f /src
parent3dfb1747939cb5b97dda29842772cfbe52c7b224 (diff)
downloadrust-7b02f29d47a05eb4cc018b362e87f3c05181e4e2.tar.gz
rust-7b02f29d47a05eb4cc018b362e87f3c05181e4e2.zip
Switch lint over to using a smallintmap.
Diffstat (limited to 'src')
-rw-r--r--src/rustc/middle/lint.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/rustc/middle/lint.rs b/src/rustc/middle/lint.rs
index 6588b9d86b7..fd98dd2e18a 100644
--- a/src/rustc/middle/lint.rs
+++ b/src/rustc/middle/lint.rs
@@ -4,6 +4,7 @@ import syntax::{ast, visit};
 import syntax::attr;
 import syntax::codemap::span;
 import std::map::{map,hashmap,int_hash,hash_from_strs};
+import std::smallintmap::{map,smallintmap};
 import io::writer_util;
 import syntax::print::pprust::expr_to_str;
 
@@ -29,6 +30,18 @@ enum lint {
     old_vecs,
 }
 
+// This is pretty unfortunate. We really want some sort of "deriving Enum"
+// type of thing.
+fn int_to_lint(i: int) -> lint {
+    alt check i {
+      0 { ctypes }
+      1 { unused_imports }
+      2 { while_true }
+      3 { path_statement }
+      4 { old_vecs }
+    }
+}
+
 enum level {
     ignore, warn, error
 }
@@ -75,12 +88,12 @@ fn get_lint_dict() -> lint_dict {
 }
 
 type ctxt = @{dict: lint_dict,
-              curr: hashmap<lint, level>,
+              curr: smallintmap<level>,
               tcx: ty::ctxt};
 
 impl methods for ctxt {
     fn get_level(lint: lint) -> level {
-        alt self.curr.find(lint) {
+        alt self.curr.find(lint as uint) {
           some(c) { c }
           none { ignore }
         }
@@ -88,9 +101,9 @@ impl methods for ctxt {
 
     fn set_level(lint: lint, level: level) {
         if level == ignore {
-            self.curr.remove(lint);
+            self.curr.remove(lint as uint);
         } else {
-            self.curr.insert(lint, level);
+            self.curr.insert(lint as uint, level);
         }
     }
 
@@ -186,7 +199,7 @@ fn time(do_it: bool, what: str, thunk: fn()) {
 fn check_item(cx: ctxt, i: @ast::item) {
     cx.with_warn_attrs(i.attrs) {|cx|
         for cx.curr.each {|lint, level|
-            alt lint {
+            alt int_to_lint(lint as int) {
               ctypes { check_item_ctypes(cx, level, i); }
               unused_imports { check_item_unused_imports(cx, level, i); }
               while_true { check_item_while_true(cx, level, i); }
@@ -338,7 +351,7 @@ fn check_crate(tcx: ty::ctxt, crate: @ast::crate,
     fn eq_lint(&&a: lint, &&b: lint) -> bool { a == b }
 
     let cx = @{dict: get_lint_dict(),
-               curr: hashmap(hash_lint, eq_lint),
+               curr: std::smallintmap::mk(),
                tcx: tcx};
 
     // Install defaults.