Skip to content

Commit

Permalink
Factor inc/dec count methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
elinorbgr committed Aug 6, 2015
1 parent 7516759 commit 8e24091
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/librustc_resolve/build_reduced_graph.rs
Expand Up @@ -928,7 +928,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
self.unresolved_imports += 1;

if is_public {
module_.pub_count.set(module_.pub_count.get() + 1);
module_.inc_pub_count();
}

// Bump the reference count on the name. Or, if this is a glob, set
Expand Down Expand Up @@ -963,9 +963,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
// Set the glob flag. This tells us that we don't know the
// module's exports ahead of time.

module_.glob_count.set(module_.glob_count.get() + 1);
module_.inc_glob_count();
if is_public {
module_.pub_glob_count.set(module_.pub_glob_count.get() + 1);
module_.inc_pub_glob_count();
}
}
}
Expand Down
24 changes: 24 additions & 0 deletions src/librustc_resolve/lib.rs
Expand Up @@ -749,6 +749,30 @@ impl Module {
}
}

impl Module {
pub fn inc_glob_count(&self) {
self.glob_count.set(self.glob_count.get() + 1);
}
pub fn dec_glob_count(&self) {
assert!(self.glob_count.get() > 0);
self.glob_count.set(self.glob_count.get() - 1);
}
pub fn inc_pub_count(&self) {
self.pub_count.set(self.pub_count.get() + 1);
}
pub fn dec_pub_count(&self) {
assert!(self.pub_count.get() > 0);
self.pub_count.set(self.pub_count.get() - 1);
}
pub fn inc_pub_glob_count(&self) {
self.pub_glob_count.set(self.pub_glob_count.get() + 1);
}
pub fn dec_pub_glob_count(&self) {
assert!(self.pub_glob_count.get() > 0);
self.pub_glob_count.set(self.pub_glob_count.get() - 1);
}
}

impl fmt::Debug for Module {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{:?}, kind: {:?}, {}",
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_resolve/resolve_imports.rs
Expand Up @@ -407,20 +407,17 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
if resolution_result.success() {
match import_directive.subclass {
GlobImport => {
assert!(module_.glob_count.get() >= 1);
module_.glob_count.set(module_.glob_count.get() - 1);
module_.dec_glob_count();
if import_directive.is_public {
assert!(module_.pub_glob_count.get() >= 1);
module_.pub_glob_count.set(module_.pub_glob_count.get() - 1);
module_.dec_pub_glob_count();
}
}
SingleImport(..) => {
// Ignore.
}
}
if import_directive.is_public {
assert!(module_.pub_count.get() >= 1);
module_.pub_count.set(module_.pub_count.get() - 1);
module_.dec_pub_count();
}
}

Expand Down

0 comments on commit 8e24091

Please sign in to comment.