提交 e29ef1be 编写于 作者: B Brian Anderson

Refactor a few things in the metadata module

Rename metadata::tags to metadata::common. Move some utility functions from
metadata::encoder to metadata::common.
上级 b723082c
// 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_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;
}
......@@ -23,7 +23,7 @@
import std::option::some;
import std::map::hashmap;
import syntax::print::pprust;
import tags::*;
import common::*;
export read_crates;
export list_file_metadata;
......
......@@ -10,11 +10,10 @@
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 eq_item(vec[u8] bytes, int item_id) -> bool {
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 eq_item(vec[u8] data, str s) -> bool {
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)));
}
......
......@@ -10,15 +10,13 @@
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();
......
......@@ -82,7 +82,7 @@ mod metadata {
export decoder;
export creader;
mod tags;
mod common;
mod tyencode;
mod tydecode;
mod encoder;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册