diff --git a/src/comp/metadata/tags.rs b/src/comp/metadata/common.rs similarity index 74% rename from src/comp/metadata/tags.rs rename to src/comp/metadata/common.rs index 27b93da73b31..5393e1d0b7ed 100644 --- a/src/comp/metadata/tags.rs +++ b/src/comp/metadata/common.rs @@ -1,4 +1,6 @@ -// EBML tag definitions shared by the encoder and decoder +// EBML tag definitions and utils shared by the encoder and decoder + +import std::str; const uint tag_paths = 0x01u; @@ -52,4 +54,14 @@ const uint tag_attribute = 0x22u; const uint tag_meta_item_word = 0x23u; -const uint tag_meta_item_list = 0x24u; \ No newline at end of file +const uint tag_meta_item_list = 0x24u; + +// djb's cdb hashes. +fn hash_node_id(&int node_id) -> uint { ret 177573u ^ (node_id as uint); } + +fn hash_path(&str s) -> uint { + auto h = 5381u; + for (u8 ch in str::bytes(s)) { h = (h << 5u) + h ^ (ch as uint); } + ret h; +} + diff --git a/src/comp/metadata/creader.rs b/src/comp/metadata/creader.rs index a59ff3d7d859..bc44560b1b4a 100644 --- a/src/comp/metadata/creader.rs +++ b/src/comp/metadata/creader.rs @@ -23,7 +23,7 @@ import std::option::none; import std::option::some; import std::map::hashmap; import syntax::print::pprust; -import tags::*; +import common::*; export read_crates; export list_file_metadata; diff --git a/src/comp/metadata/decoder.rs b/src/comp/metadata/decoder.rs index b8174139e5ee..cc3c103ac56a 100644 --- a/src/comp/metadata/decoder.rs +++ b/src/comp/metadata/decoder.rs @@ -10,11 +10,10 @@ import std::map::hashmap; import syntax::ast; import front::attr; import middle::ty; -import tags::*; +import common::*; import tydecode::parse_def_id; import tydecode::parse_ty_data; import driver::session; -import util::common; import syntax::print::pprust; export get_symbol; @@ -51,7 +50,7 @@ fn maybe_find_item(int item_id, &ebml::doc items) -> option::t[ebml::doc] { ret ebml::be_uint_from_bytes(bytes, 0u, 4u) as int == item_id; } auto eqer = bind eq_item(_, item_id); - auto found = lookup_hash(items, eqer, encoder::hash_node_id(item_id)); + auto found = lookup_hash(items, eqer, hash_node_id(item_id)); if (vec::len(found) == 0u) { ret option::none[ebml::doc]; } else { ret option::some[ebml::doc](found.(0)); } @@ -129,7 +128,7 @@ fn resolve_path(vec[ast::ident] path, vec[u8] data) -> vec[ast::def_id] { auto paths = ebml::get_doc(md, tag_paths); auto eqer = bind eq_item(_, s); let vec[ast::def_id] result = []; - for (ebml::doc doc in lookup_hash(paths, eqer, encoder::hash_path(s))) { + for (ebml::doc doc in lookup_hash(paths, eqer, hash_path(s))) { auto did_doc = ebml::get_doc(doc, tag_def_id); vec::push(result, parse_def_id(ebml::doc_data(did_doc))); } diff --git a/src/comp/metadata/encoder.rs b/src/comp/metadata/encoder.rs index dc7c39279921..ed90eaf1263f 100644 --- a/src/comp/metadata/encoder.rs +++ b/src/comp/metadata/encoder.rs @@ -10,15 +10,13 @@ import std::option::some; import std::option::none; import std::ebml; import syntax::ast::*; -import tags::*; +import common::*; import middle::trans::crate_ctxt; import middle::ty; import middle::ty::node_id_to_monotype; import front::attr; export def_to_str; -export hash_path; -export hash_node_id; export encode_metadata; // Path table encoding @@ -370,15 +368,6 @@ fn encode_info_for_items(&@crate_ctxt cx, &ebml::writer ebml_w) -> // Path and definition ID indexing -// djb's cdb hashes. -fn hash_node_id(&int node_id) -> uint { ret 177573u ^ (node_id as uint); } - -fn hash_path(&str s) -> uint { - auto h = 5381u; - for (u8 ch in str::bytes(s)) { h = (h << 5u) + h ^ (ch as uint); } - ret h; -} - fn create_index[T](&vec[tup(T, uint)] index, fn(&T) -> uint hash_fn) -> vec[vec[tup(T, uint)]] { let vec[mutable vec[tup(T, uint)]] buckets = vec::empty_mut(); diff --git a/src/comp/rustc.rc b/src/comp/rustc.rc index 69336c5cb614..b5f104745c42 100644 --- a/src/comp/rustc.rc +++ b/src/comp/rustc.rc @@ -82,7 +82,7 @@ mod metadata { export decoder; export creader; - mod tags; + mod common; mod tyencode; mod tydecode; mod encoder;