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"))]
Union::Shared(cell, _) => {
#[cfg(not(feature = "sync"))]
{
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()),
}
}
let data = cell.borrow();
#[cfg(feature = "sync")]
{
let inner = cell.read().unwrap();
match &inner.0 {
Union::Str(s, _) => Ok(s.clone()),
Union::FnPtr(f, _) => Ok(f.clone().take_data().0),
_ => Err((*inner).type_name()),
}
let data = cell.read().unwrap();
match &data.0 {
Union::Str(s, _) => Ok(s.clone()),
Union::FnPtr(f, _) => Ok(f.get_fn_name().clone()),
_ => Err((*data).type_name()),
}
}
_ => Err(self.type_name()),