提交 8e24091f 编写于 作者: V Victor Berger

Factor inc/dec count methods.

上级 75167593
......@@ -928,7 +928,7 @@ fn build_import_directive(&mut self,
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 @@ fn build_import_directive(&mut self,
// 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();
}
}
}
......
......@@ -749,6 +749,30 @@ fn all_imports_resolved(&self) -> bool {
}
}
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: {:?}, {}",
......
......@@ -407,11 +407,9 @@ fn resolve_import_for_module(&mut self,
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 @@ fn resolve_import_for_module(&mut self,
}
}
if import_directive.is_public {
assert!(module_.pub_count.get() >= 1);
module_.pub_count.set(module_.pub_count.get() - 1);
module_.dec_pub_count();
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册