[MLton-commit] r6017

Vesa Karvonen vesak at mlton.org
Thu Sep 13 01:12:01 PDT 2007


Avoid constructing a proxy ref cell (holding a dummy value) when
unpickling acyclic refs.

A similar optimization could also be done for arrays, but it is probably
more efficient to construct an array holding dummy values and then update
the array incrementally rather than accumulate a list of values and then
construct an array from the list.

This could also be seen as a correctness / semantics issue.  The
construction of a dummy value (using the Some generic) might actually
fail.  So, it makes sense to avoid constructing dummy values when they are
not strictly needed.

----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml

----------------------------------------------------------------------

Modified: mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml
===================================================================
--- mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml	2007-09-12 18:41:07 UTC (rev 6016)
+++ mltonlib/trunk/com/ssh/generic/unstable/detail/value/pickle.sml	2007-09-13 08:12:00 UTC (rev 6017)
@@ -600,11 +600,14 @@
 
       fun refc aT = let
          val P {rd, wr, ...} = getT aT
+         val self = Arg.refc ignore aT
       in
-          mutable {readProxy = I.thunk (ref o const (Arg.some aT)),
-                   readBody = fn proxy => I.map (fn v => proxy := v) rd,
-                   writeWhole = wr o !,
-                   self = Arg.refc ignore aT}
+         if Arg.mayBeCyclic self
+         then cyclic {readProxy = I.thunk (ref o const (Arg.some aT)),
+                      readBody = fn proxy => I.map (fn v => proxy := v) rd,
+                      writeWhole = wr o !,
+                      self = self}
+         else share self (P {rd = I.map ref rd, wr = wr o !, sz = NONE})
       end
 
       fun array aT = let




More information about the MLton-commit mailing list