summaryrefslogtreecommitdiff
path: root/dhall
diff options
context:
space:
mode:
authorNadrieril2019-04-30 18:02:08 +0200
committerNadrieril2019-04-30 18:05:19 +0200
commitba0c760e9dc30a4babf9b76860153aa05d16e9eb (patch)
tree22f1c45b30e34a3b953575bf1f41cebe9868b526 /dhall
parent1821d87055d0090f0f9c40428706eb0a9da5d28b (diff)
Mutate thunk contents directly if sole owner
Diffstat (limited to 'dhall')
-rw-r--r--dhall/src/normalize.rs10
1 files changed, 8 insertions, 2 deletions
diff --git a/dhall/src/normalize.rs b/dhall/src/normalize.rs
index 7fef48e..c89e147 100644
--- a/dhall/src/normalize.rs
+++ b/dhall/src/normalize.rs
@@ -1032,9 +1032,15 @@ mod thunk {
self.clone()
}
+ // Normalizes contents to normal form; faster than `normalize_nf` if
+ // no one else shares this thunk
pub(crate) fn normalize_mut(&mut self) {
- // TODO: optimize if sole owner
- self.normalize_nf();
+ match Rc::get_mut(&mut self.0) {
+ // Mutate directly if sole owner
+ Some(refcell) => RefCell::get_mut(refcell).normalize_nf(),
+ // Otherwise mutate through the refcell
+ None => self.0.borrow_mut().normalize_nf(),
+ }
}
// WARNING: avoid normalizing any thunk while holding on to this ref