diff options
| author | Brian Anderson <banderson@mozilla.com> | 2011-07-07 12:22:39 -0700 |
|---|---|---|
| committer | Brian Anderson <banderson@mozilla.com> | 2011-07-07 13:31:11 -0700 |
| commit | e29ef1bec276ddbb77bb4663aeb0208dccdaf9ac (patch) | |
| tree | 2c46f88cf848cd735282ada43ee8295e8d76e83f /src/comp | |
| parent | b723082cdb2d5793c103f64f9709639f97e31c61 (diff) | |
| download | rust-e29ef1bec276ddbb77bb4663aeb0208dccdaf9ac.tar.gz rust-e29ef1bec276ddbb77bb4663aeb0208dccdaf9ac.zip | |
Refactor a few things in the metadata module
Rename metadata::tags to metadata::common. Move some utility functions from metadata::encoder to metadata::common.
Diffstat (limited to 'src/comp')
| -rw-r--r-- | src/comp/metadata/common.rs (renamed from src/comp/metadata/tags.rs) | 16 | ||||
| -rw-r--r-- | src/comp/metadata/creader.rs | 2 | ||||
| -rw-r--r-- | src/comp/metadata/decoder.rs | 7 | ||||
| -rw-r--r-- | src/comp/metadata/encoder.rs | 13 | ||||
| -rw-r--r-- | src/comp/rustc.rc | 2 |
5 files changed, 20 insertions, 20 deletions
diff --git a/src/comp/metadata/tags.rs b/src/comp/metadata/common.rs index 27b93da73b3..5393e1d0b7e 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 a59ff3d7d85..bc44560b1b4 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 b8174139e5e..cc3c103ac56 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 dc7c3927992..ed90eaf1263 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 69336c5cb61..b5f104745c4 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; |
