Share constant variables for closures.
This commit is contained in:
@@ -615,7 +615,20 @@ impl Dynamic {
|
||||
/// if its value is going to be modified. This safe-guards constant values from being modified
|
||||
/// from within Rust functions.
|
||||
pub fn is_read_only(&self) -> bool {
|
||||
self.access_mode().is_read_only()
|
||||
match self.0 {
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Union::Shared(_, access) if access.is_read_only() => true,
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(not(feature = "sync"))]
|
||||
Union::Shared(ref cell, _) => cell.borrow().access_mode().is_read_only(),
|
||||
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
#[cfg(feature = "sync")]
|
||||
Union::Shared(ref cell, _) => cell.read().unwrap().access_mode().is_read_only(),
|
||||
|
||||
_ => self.access_mode().is_read_only(),
|
||||
}
|
||||
}
|
||||
/// Create a [`Dynamic`] from any type. A [`Dynamic`] value is simply returned as is.
|
||||
///
|
||||
|
@@ -2383,16 +2383,13 @@ impl Engine {
|
||||
// Share statement
|
||||
#[cfg(not(feature = "no_closure"))]
|
||||
Stmt::Share(x) => {
|
||||
match scope.get_index(&x.name) {
|
||||
Some((index, AccessMode::ReadWrite)) => {
|
||||
let val = scope.get_mut(index);
|
||||
if let Some((index, _)) = scope.get_index(&x.name) {
|
||||
let val = scope.get_mut(index);
|
||||
|
||||
if !val.is_shared() {
|
||||
// Replace the variable with a shared value.
|
||||
*val = crate::stdlib::mem::take(val).into_shared();
|
||||
}
|
||||
if !val.is_shared() {
|
||||
// Replace the variable with a shared value.
|
||||
*val = crate::stdlib::mem::take(val).into_shared();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
Ok(Dynamic::UNIT)
|
||||
}
|
||||
|
Reference in New Issue
Block a user