[MLton-commit] r4843

Vesa Karvonen vesak at mlton.org
Sun Nov 19 12:03:59 PST 2006


Added pushBuffer and pushList.
----------------------------------------------------------------------

U   mltonlib/trunk/com/ssh/basic/unstable/detail/buffer.sml
U   mltonlib/trunk/com/ssh/basic/unstable/public/buffer.sig

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

Modified: mltonlib/trunk/com/ssh/basic/unstable/detail/buffer.sml
===================================================================
--- mltonlib/trunk/com/ssh/basic/unstable/detail/buffer.sml	2006-11-19 20:03:10 UTC (rev 4842)
+++ mltonlib/trunk/com/ssh/basic/unstable/detail/buffer.sml	2006-11-19 20:03:55 UTC (rev 4843)
@@ -28,22 +28,30 @@
                end
    end
    local
-      fun mk sLength sSub sCopy (b as IN {length, data}, s) =
+      fun mk sLength sAny sCopy (b as IN {length, data}, s) =
           case sLength s of
              0 => ()
            | n => let
                 val newLength = !length + n
-             in ensureCap b newLength (sSub (s, 0))
+             in ensureCap b newLength (sAny s)
               ; sCopy {src = s, dst = !data, di = !length} : unit
               ; length := newLength
              end
+      infixr />
+      val op /> = Fn./>
    in
-      fun push ? = mk (Fn.const 1) Pair.fst
-                      (fn {src, dst, di} => A.update (dst, di, src)) ?
-      fun pushArray ? = mk A.length A.sub A.copy ?
-      fun pushArraySlice ? = mk AS.length AS.sub AS.copy ?
-      fun pushVector ? = mk V.length V.sub A.copyVec ?
-      fun pushVectorSlice ? = mk VS.length VS.sub AS.copyVec ?
+      fun push ? =
+          mk (Fn.const 1) Fn.id (fn {src, dst, di} => A.update (dst, di, src)) ?
+      fun pushArray ? = mk A.length (A.sub /> 0) A.copy ?
+      fun pushArraySlice ? = mk AS.length (AS.sub /> 0) AS.copy ?
+      fun pushBuffer (b, s) =
+          pushArraySlice (b, AS.slice (data s, 0, SOME (length s)))
+      fun pushList ? =
+          mk List.length List.hd
+             (fn {src, dst, di} =>
+                 List.appi (fn (i, x) => A.update (dst, di+i, x)) src) ?
+      fun pushVector ? = mk V.length (V.sub /> 0) A.copyVec ?
+      fun pushVectorSlice ? = mk VS.length (VS.sub /> 0) AS.copyVec ?
    end
    local
       fun mk tabulate b = tabulate (length b, fn i => sub (b, i))

Modified: mltonlib/trunk/com/ssh/basic/unstable/public/buffer.sig
===================================================================
--- mltonlib/trunk/com/ssh/basic/unstable/public/buffer.sig	2006-11-19 20:03:10 UTC (rev 4842)
+++ mltonlib/trunk/com/ssh/basic/unstable/public/buffer.sig	2006-11-19 20:03:55 UTC (rev 4843)
@@ -20,6 +20,8 @@
 
    val pushArray : ('a t * 'a Array.t) Effect.t
    val pushArraySlice : ('a t * 'a ArraySlice.t) Effect.t
+   val pushBuffer : ('a t * 'a t) Effect.t
+   val pushList : ('a t * 'a List.t) Effect.t
    val pushVector : ('a t * 'a Vector.t) Effect.t
    val pushVectorSlice : ('a t * 'a VectorSlice.t) Effect.t
 




More information about the MLton-commit mailing list