[MLton-commit] r4415

Stephen Weeks MLton@mlton.org
Tue, 25 Apr 2006 10:35:48 -0700


Tweaked to use the same "offset" function for PackReal and PackWord.

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

U   mlton/trunk/basis-library/integer/pack-word32.sml
U   mlton/trunk/basis-library/real/pack-real.sml

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

Modified: mlton/trunk/basis-library/integer/pack-word32.sml
===================================================================
--- mlton/trunk/basis-library/integer/pack-word32.sml	2006-04-25 17:24:44 UTC (rev 4414)
+++ mlton/trunk/basis-library/integer/pack-word32.sml	2006-04-25 17:35:46 UTC (rev 4415)
@@ -22,14 +22,16 @@
          Primitive.Word8Array.updateWordRev,
          Primitive.Word8Vector.subWordRev)
 
-fun start (i, n) = 
+fun offset (i, n) = 
    let
       val i = Int.* (bytesPerElem, i)
-      val _ =
+      val () =
          if Primitive.safe
-            andalso Primitive.Int.geu (Int.+ (i, Int.- (bytesPerElem, 1)), n)
-            then raise Subscript
-         else ()
+            andalso (Primitive.Int.geu
+                     (Int.+ (i, Int.- (bytesPerElem, 1)), n)) then
+            raise Subscript
+         else
+            ()
    in
       i
    end handle Overflow => raise Subscript
@@ -37,7 +39,7 @@
 local
    fun make (sub, length, toPoly) (av, i) =
       let
-         val _ = start (i, length av)
+         val _ = offset (i, length av)
       in
          Word.toLarge (sub (toPoly av, i))
       end
@@ -51,7 +53,7 @@
 fun update (a, i, w) =
    let
       val a = Word8Array.toPoly a
-      val _ = start (i, Array.length a)
+      val _ = offset (i, Array.length a)
    in
       up (a, i, Word.fromLarge w)
    end

Modified: mlton/trunk/basis-library/real/pack-real.sml
===================================================================
--- mlton/trunk/basis-library/real/pack-real.sml	2006-04-25 17:24:44 UTC (rev 4414)
+++ mlton/trunk/basis-library/real/pack-real.sml	2006-04-25 17:35:46 UTC (rev 4415)
@@ -24,19 +24,23 @@
       then (subVec, update)
    else (subVecRev, updateRev)
 
-fun offset (size, i) =
+fun offset (i, n) =
    let
-      val off = Int.* (bytesPerElem, i)
+      val i = Int.* (bytesPerElem, i)
+      val () =
+         if Primitive.safe
+            andalso (Primitive.Int.geu
+                     (Int.+ (i, Int.- (bytesPerElem, 1)), n)) then
+            raise Subscript
+         else
+            ()
    in
-      if Int.< (i, 0) orelse Int.> (off, size -? bytesPerElem) 
-         then raise Subscript
-         else off
-   end
-   handle Overflow => raise Subscript
+      i
+   end handle Overflow => raise Subscript
 
 fun update (a, i, r) =
    let
-      val i = offset (Word8Array.length a, i)
+      val i = offset (i, Word8Array.length a)
       val a = Word8Array.toPoly a
    in
       up (a, i, r)
@@ -52,7 +56,7 @@
 
 fun subVec (v, i) =
    let
-      val i = offset (Word8Vector.length v, i)
+      val i = offset (i, Word8Vector.length v)
       val v = Word8Vector.toPoly v
    in
       sub (v, i)