[MLton-commit] r6971

Vesa Karvonen vesak at mlton.org
Sun Nov 2 05:40:05 PST 2008


Optimized the hash function to avoid allocating a string.  Although this
seems to slightly increase collisions, this also seems to reduce total
allocation on a self compile by about 2.5GB and reduce the total compile
time.

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

U   mlton/trunk/lib/mlton/basic/int-inf.sml

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

Modified: mlton/trunk/lib/mlton/basic/int-inf.sml
===================================================================
--- mlton/trunk/lib/mlton/basic/int-inf.sml	2008-11-02 13:33:42 UTC (rev 6970)
+++ mlton/trunk/lib/mlton/basic/int-inf.sml	2008-11-02 13:40:05 UTC (rev 6971)
@@ -10,9 +10,21 @@
 
 structure IntInf: INT_INF =
    struct
-      open IntInf 
+      open IntInf
 
-      val hash = String.hash o toString
+      val hash = let
+         val prime =
+             (Word.toIntInf o Word.~ o Word.fromInt)
+              (case Word.wordSize of
+                  8 => 5
+                | 16 => 15
+                | 32 => 5
+                | 64 => 59
+                | 128 => 159
+                | _ => Error.bug "Unknown Word.wordSize")
+      in
+         fn i => Word.fromIntInf (i mod prime)
+      end
 
       local
          open Pervasive.IntInf




More information about the MLton-commit mailing list