Simplify target back propagation.
This commit is contained in:
parent
d802829156
commit
a962debf0d
@ -150,6 +150,7 @@ pub enum Target<'a> {
|
|||||||
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
#[cfg(any(not(feature = "no_index"), not(feature = "no_object")))]
|
||||||
impl Target<'_> {
|
impl Target<'_> {
|
||||||
/// Is the `Target` a reference pointing to other data?
|
/// Is the `Target` a reference pointing to other data?
|
||||||
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_ref(&self) -> bool {
|
pub fn is_ref(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -163,6 +164,7 @@ impl Target<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is the `Target` an owned value?
|
/// Is the `Target` an owned value?
|
||||||
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_value(&self) -> bool {
|
pub fn is_value(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -176,6 +178,7 @@ impl Target<'_> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
/// Is the `Target` a shared value?
|
/// Is the `Target` a shared value?
|
||||||
|
#[allow(dead_code)]
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_shared(&self) -> bool {
|
pub fn is_shared(&self) -> bool {
|
||||||
match self {
|
match self {
|
||||||
@ -228,6 +231,19 @@ impl Target<'_> {
|
|||||||
Self::StringChar(_, _, ref mut r) => r,
|
Self::StringChar(_, _, ref mut r) => r,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/// Propagate a changed value back to the original source.
|
||||||
|
/// This has no effect except for string indexing.
|
||||||
|
pub fn propagate_changed_value(&mut self) {
|
||||||
|
match self {
|
||||||
|
Self::Ref(_) | Self::LockGuard(_) | Self::Value(_) => (),
|
||||||
|
#[cfg(not(feature = "no_index"))]
|
||||||
|
Self::StringChar(_, _, ch) => {
|
||||||
|
let new_val = ch.clone();
|
||||||
|
self.set_value(new_val, Position::none(), Position::none())
|
||||||
|
.unwrap();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
/// Update the value of the `Target`.
|
/// Update the value of the `Target`.
|
||||||
pub fn set_value(
|
pub fn set_value(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
@ -670,7 +670,6 @@ impl Engine {
|
|||||||
level: usize,
|
level: usize,
|
||||||
) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
) -> Result<(Dynamic, bool), Box<EvalAltResult>> {
|
||||||
let is_ref = target.is_ref();
|
let is_ref = target.is_ref();
|
||||||
let is_value = target.is_value();
|
|
||||||
|
|
||||||
// Get a reference to the mutation target Dynamic
|
// Get a reference to the mutation target Dynamic
|
||||||
let obj = target.as_mut();
|
let obj = target.as_mut();
|
||||||
@ -793,10 +792,9 @@ impl Engine {
|
|||||||
)
|
)
|
||||||
}?;
|
}?;
|
||||||
|
|
||||||
// Feed the changed temp value back
|
// Propagate the changed value back to the source if necessary
|
||||||
if updated && !is_ref && !is_value {
|
if updated {
|
||||||
let new_val = target.as_mut().clone();
|
target.propagate_changed_value();
|
||||||
target.set_value(new_val, Position::none(), Position::none())?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok((result, updated))
|
Ok((result, updated))
|
||||||
|
Loading…
Reference in New Issue
Block a user