Factor inc/dec count methods.

This commit is contained in:
Victor Berger 2015-08-06 12:47:10 +02:00
parent 751675938e
commit 8e24091f98
3 changed files with 30 additions and 9 deletions

View File

@ -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
@ -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();
}
}
}

View File

@ -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: {:?}, {}",

View File

@ -407,11 +407,9 @@ 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(..) => {
@ -419,8 +417,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
}
}
if import_directive.is_public {
assert!(module_.pub_count.get() >= 1);
module_.pub_count.set(module_.pub_count.get() - 1);
module_.dec_pub_count();
}
}