Skip to content

Commit 8869e72

Browse files
committed
Simplify path_entry's closure argument
Make the closure take two arguments instead of a single `path_entry` struct; remove the `path_entry` type. This eliminates a bad copy.
1 parent e02449c commit 8869e72

File tree

4 files changed

+19
-39
lines changed

4 files changed

+19
-39
lines changed

src/librustc/metadata/csearch.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ fn each_lang_item(cstore: cstore::CStore,
8888

8989
/// Iterates over all the paths in the given crate.
9090
fn each_path(cstore: cstore::CStore, cnum: ast::crate_num,
91-
f: fn(decoder::path_entry) -> bool) {
91+
f: fn(&str, decoder::def_like) -> bool) {
9292
let crate_data = cstore::get_crate_data(cstore, cnum);
9393
let get_crate_data: decoder::GetCrateDataCb = |cnum| {
9494
cstore::get_crate_data(cstore, cnum)

src/librustc/metadata/decoder.rs

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ export def_like;
7575
export dl_def;
7676
export dl_impl;
7777
export dl_field;
78-
export path_entry;
7978
export each_lang_item;
8079
export each_path;
8180
export get_item_path;
@@ -468,21 +467,6 @@ fn def_like_to_def(def_like: def_like) -> ast::def {
468467
}
469468
}
470469

471-
// A path.
472-
struct path_entry {
473-
// The full path, separated by '::'.
474-
path_string: ~str,
475-
// The definition, implementation, or field that this path corresponds to.
476-
def_like: def_like,
477-
}
478-
479-
fn path_entry(+path_string: ~str, def_like: def_like) -> path_entry {
480-
path_entry {
481-
path_string: path_string,
482-
def_like: def_like
483-
}
484-
}
485-
486470
/// Iterates over the language items in the given crate.
487471
fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) {
488472
let root = reader::Doc(cdata.data);
@@ -503,7 +487,7 @@ fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) {
503487
/// Iterates over all the paths in the given crate.
504488
fn each_path(intr: @ident_interner, cdata: cmd,
505489
get_crate_data: GetCrateDataCb,
506-
f: fn(path_entry) -> bool) {
490+
f: fn(&str, def_like) -> bool) {
507491
let root = reader::Doc(cdata.data);
508492
let items = reader::get_doc(root, tag_items);
509493
let items_data = reader::get_doc(items, tag_items_data);
@@ -515,7 +499,8 @@ fn each_path(intr: @ident_interner, cdata: cmd,
515499
if !broken {
516500
let path = ast_map::path_to_str_with_sep(
517501
item_path(intr, item_doc), ~"::", intr);
518-
if path != ~"" {
502+
let path_is_empty = path.is_empty();
503+
if !path_is_empty {
519504
// Extract the def ID.
520505
let def_id = item_def_id(item_doc, cdata);
521506

@@ -524,10 +509,8 @@ fn each_path(intr: @ident_interner, cdata: cmd,
524509
let def_like = item_to_def_like(item_doc, def_id, cdata.cnum);
525510

526511
// Hand the information off to the iteratee.
527-
// XXX: Bad copy.
528-
let this_path_entry = path_entry(copy path, def_like);
529-
if !f(this_path_entry) {
530-
broken = true; // XXX: This is awful.
512+
if !f(path, def_like) {
513+
broken = true; // FIXME #4572: This is awful.
531514
}
532515
}
533516

@@ -548,7 +531,7 @@ fn each_path(intr: @ident_interner, cdata: cmd,
548531
let reexport_name = reader::doc_as_str(reexport_name_doc);
549532

550533
let reexport_path;
551-
if path == ~"" {
534+
if path_is_empty {
552535
reexport_path = reexport_name;
553536
} else {
554537
reexport_path = path + ~"::" + reexport_name;
@@ -576,10 +559,8 @@ fn each_path(intr: @ident_interner, cdata: cmd,
576559
debug!("(each_path) yielding reexported \
577560
item: %s", reexport_path);
578561

579-
let this_path_entry =
580-
path_entry(reexport_path, def_like);
581-
if (!f(this_path_entry)) {
582-
broken = true; // XXX: This is awful.
562+
if (!f(reexport_path, def_like)) {
563+
broken = true; // FIXME #4572: This is awful.
583564
}
584565
}
585566
}
@@ -1123,12 +1104,12 @@ fn get_crate_vers(data: @~[u8]) -> ~str {
11231104

11241105
fn iter_crate_items(intr: @ident_interner, cdata: cmd,
11251106
get_crate_data: GetCrateDataCb,
1126-
proc: fn(+path: ~str, ast::def_id)) {
1127-
for each_path(intr, cdata, get_crate_data) |path_entry| {
1128-
match path_entry.def_like {
1107+
proc: fn(path: &str, ast::def_id)) {
1108+
for each_path(intr, cdata, get_crate_data) |path_string, def_like| {
1109+
match def_like {
11291110
dl_impl(*) | dl_field => {}
11301111
dl_def(def) => {
1131-
proc(/*bad*/copy path_entry.path_string,
1112+
proc(path_string,
11321113
ast_util::def_id_of_def(def))
11331114
}
11341115
}

src/librustc/middle/resolve.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1808,14 +1808,13 @@ impl Resolver {
18081808

18091809
// Create all the items reachable by paths.
18101810
for each_path(self.session.cstore, root.def_id.get().crate)
1811-
|path_entry| {
1811+
|path_string, def_like| {
18121812

18131813
debug!("(building reduced graph for external crate) found path \
18141814
entry: %s (%?)",
1815-
path_entry.path_string,
1816-
path_entry.def_like);
1815+
path_string, def_like);
18171816

1818-
let mut pieces = split_str(path_entry.path_string, ~"::");
1817+
let mut pieces = split_str(path_string, ~"::");
18191818
let final_ident_str = pieces.pop();
18201819
let final_ident = self.session.ident_of(final_ident_str);
18211820

@@ -1867,7 +1866,7 @@ impl Resolver {
18671866
current_module = (*child_name_bindings).get_module();
18681867
}
18691868

1870-
match path_entry.def_like {
1869+
match def_like {
18711870
dl_def(def) => {
18721871
// Add the new child item.
18731872
let (child_name_bindings, new_parent) =

src/librustc/middle/typeck/coherence.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -931,8 +931,8 @@ impl CoherenceChecker {
931931
def_id { crate: crate_number,
932932
node: 0 });
933933

934-
for each_path(crate_store, crate_number) |path_entry| {
935-
match path_entry.def_like {
934+
for each_path(crate_store, crate_number) |_p, def_like| {
935+
match def_like {
936936
dl_def(def_mod(def_id)) => {
937937
self.add_impls_for_module(impls_seen,
938938
crate_store,

0 commit comments

Comments
 (0)