-
-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #86 from ivanceras/pre_eval-clone
This adds prediff feature for sauron. This is the first step towards optimization of skipping nodes for diffing by checking the App fields alone.
- Loading branch information
Showing
57 changed files
with
1,095 additions
and
151 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
use mt_dom::TreePath; | ||
use std::fmt; | ||
|
||
/// | ||
pub struct PreDiff { | ||
expr: Box<dyn Fn() -> bool>, | ||
children: Vec<PreDiff>, | ||
} | ||
|
||
impl fmt::Debug for PreDiff { | ||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | ||
write!(f, "({}", (self.expr)())?; | ||
write!(f, ",[")?; | ||
for child in &self.children { | ||
child.fmt(f)?; | ||
} | ||
write!(f, "])")?; | ||
Ok(()) | ||
} | ||
} | ||
|
||
impl PreDiff { | ||
/// new | ||
pub fn new(val: bool, children: impl IntoIterator<Item = Self>) -> Self { | ||
Self { | ||
expr: Box::new(move || val), | ||
children: children.into_iter().collect(), | ||
} | ||
} | ||
|
||
/// | ||
pub fn none() -> Self { | ||
PreDiff { | ||
expr: Box::new(|| false), | ||
children: vec![], | ||
} | ||
} | ||
|
||
/// | ||
pub fn traverse(evals: &[PreDiff]) -> Vec<TreePath> { | ||
let root = TreePath::root(); | ||
if evals.len() == 1 { | ||
Self::traverse_recursive(&evals[0], root) | ||
} else { | ||
Self::traverse_list(evals, root) | ||
} | ||
} | ||
|
||
/// | ||
fn traverse_list(evals: &[PreDiff], current: TreePath) -> Vec<TreePath> { | ||
let mut paths = vec![]; | ||
for (i, eval) in evals.iter().enumerate() { | ||
let more_paths = eval.traverse_recursive(current.traverse(i)); | ||
paths.extend(more_paths); | ||
} | ||
paths | ||
} | ||
|
||
fn traverse_recursive(&self, current: TreePath) -> Vec<TreePath> { | ||
let mut paths = vec![]; | ||
if (self.expr)() { | ||
paths.push(current.clone()); | ||
} | ||
let more_paths = Self::traverse_list(&self.children, current); | ||
paths.extend(more_paths); | ||
paths | ||
} | ||
} | ||
|
||
/// evaluate check | ||
pub fn diff_if(val: bool, children: impl IntoIterator<Item = PreDiff>) -> PreDiff { | ||
PreDiff::new(val, children) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.