[MLton-commit] r6605

Matthew Fluet fluet at mlton.org
Tue Apr 22 17:23:03 PDT 2008


Replace for-loop with a do-while loop.

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

U   mlton/trunk/runtime/gc/heap.c

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

Modified: mlton/trunk/runtime/gc/heap.c
===================================================================
--- mlton/trunk/runtime/gc/heap.c	2008-04-23 00:22:59 UTC (rev 6604)
+++ mlton/trunk/runtime/gc/heap.c	2008-04-23 00:23:02 UTC (rev 6605)
@@ -169,7 +169,8 @@
    * to fail.  This is important for large heaps.
    * Note that the loop always trys a NULL address last.
    */
-  for (h->size = desiredSize; h->size >= minSize; h->size -= backoff) {
+  h->size = desiredSize;
+  do {
     const unsigned int countLog2 = 5;
     const unsigned int count = 0x1 << countLog2;
     const size_t step = (size_t)0x1 << (ADDRESS_BITS - countLog2);
@@ -218,11 +219,20 @@
                uintmaxToCommaString (backoff),
                uintmaxToCommaString (minSize));
     }
-    /* For the last round, try to allocate minSize (and no more). */
     if (h->size > minSize
-        and (h->size - backoff) < minSize)
-      backoff = h->size - minSize;
-  }
+        and (h->size - backoff) < minSize) {
+      h->size = minSize;
+    } else {
+      h->size -= backoff;
+    }
+
+    size_t nextSize = h->size - backoff;
+    if (nextSize < minSize and minSize < h->size) {
+      h->size = minSize;
+    } else {
+      h->size = nextSize;
+    }
+  } while (h->size >= minSize);
   h->size = 0;
   return FALSE;
 }




More information about the MLton-commit mailing list