Refine Dynamic::take_immutable_string when shared.

This commit is contained in:
Stephen Chung 2021-01-27 18:34:32 +08:00
parent 2a209b82e9
commit d14168a419

View File

@ -1337,22 +1337,14 @@ impl Dynamic {
#[cfg(not(feature = "no_closure"))] #[cfg(not(feature = "no_closure"))]
Union::Shared(cell, _) => { Union::Shared(cell, _) => {
#[cfg(not(feature = "sync"))] #[cfg(not(feature = "sync"))]
{ let data = cell.borrow();
let inner = cell.borrow();
match &inner.0 {
Union::Str(s, _) => Ok(s.clone()),
Union::FnPtr(f, _) => Ok(f.clone().take_data().0),
_ => Err((*inner).type_name()),
}
}
#[cfg(feature = "sync")] #[cfg(feature = "sync")]
{ let data = cell.read().unwrap();
let inner = cell.read().unwrap();
match &inner.0 { match &data.0 {
Union::Str(s, _) => Ok(s.clone()), Union::Str(s, _) => Ok(s.clone()),
Union::FnPtr(f, _) => Ok(f.clone().take_data().0), Union::FnPtr(f, _) => Ok(f.get_fn_name().clone()),
_ => Err((*inner).type_name()), _ => Err((*data).type_name()),
}
} }
} }
_ => Err(self.type_name()), _ => Err(self.type_name()),