Add checks for is_empty.

This commit is contained in:
Stephen Chung
2022-03-03 13:02:57 +08:00
parent 83755bf936
commit 0e9a16e437
18 changed files with 202 additions and 110 deletions

View File

@@ -206,14 +206,10 @@ enum DynamicReadLockInner<'d, T: Clone> {
/// A simple reference to a non-shared value.
Reference(&'d T),
/// A read guard to a shared [`RefCell`][std::cell::RefCell].
/// A read guard to a shared value.
#[cfg(not(feature = "no_closure"))]
#[cfg(not(feature = "sync"))]
Guard(std::cell::Ref<'d, Dynamic>),
/// A read guard to a shared [`RwLock`][std::sync::RwLock].
#[cfg(not(feature = "no_closure"))]
#[cfg(feature = "sync")]
Guard(std::sync::RwLockReadGuard<'d, Dynamic>),
Guard(crate::func::native::LockGuard<'d, Dynamic>),
}
impl<'d, T: Any + Clone> Deref for DynamicReadLock<'d, T> {
@@ -245,7 +241,7 @@ enum DynamicWriteLockInner<'d, T: Clone> {
/// A write guard to a shared value.
#[cfg(not(feature = "no_closure"))]
Guard(crate::func::native::LockGuard<'d, Dynamic>),
Guard(crate::func::native::LockGuardMut<'d, Dynamic>),
}
impl<'d, T: Any + Clone> Deref for DynamicWriteLock<'d, T> {

View File

@@ -59,7 +59,7 @@ impl StringsInterner {
_ => unreachable!("unsupported prefix {}", prefix.as_ref()),
};
if dict.contains_key(text.as_ref()) {
if !dict.is_empty() && dict.contains_key(text.as_ref()) {
dict.get(text.as_ref()).unwrap().clone()
} else {
let value: ImmutableString = mapper(text.as_ref()).into();

View File

@@ -516,7 +516,7 @@ impl Scope<'_> {
#[inline]
pub(crate) fn add_entry_alias(&mut self, index: usize, alias: Identifier) -> &mut Self {
let aliases = self.aliases.get_mut(index).unwrap();
if !aliases.contains(&alias) {
if aliases.is_empty() || !aliases.contains(&alias) {
aliases.push(alias);
}
self
@@ -533,7 +533,7 @@ impl Scope<'_> {
.rev()
.enumerate()
.fold(Self::new(), |mut entries, (index, name)| {
if !entries.names.contains(name) {
if entries.names.is_empty() || !entries.names.contains(name) {
let orig_value = &self.values[len - 1 - index];
let alias = &self.aliases[len - 1 - index];
let mut value = orig_value.clone();