[svn:parrot] r45312 - trunk/src/gc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Tue Mar 30 07:49:13 UTC 2010


Author: chromatic
Date: Tue Mar 30 07:49:13 2010
New Revision: 45312
URL: https://trac.parrot.org/parrot/changeset/45312

Log:
[GC] Tidied code; no functional changes.

Modified:
   trunk/src/gc/alloc_resources.c
   trunk/src/gc/gc_ms.c

Modified: trunk/src/gc/alloc_resources.c
==============================================================================
--- trunk/src/gc/alloc_resources.c	Tue Mar 30 07:49:10 2010	(r45311)
+++ trunk/src/gc/alloc_resources.c	Tue Mar 30 07:49:13 2010	(r45312)
@@ -464,7 +464,6 @@
     mem_pools->header_allocs_since_last_collect = 0;
     mem_pools->gc_collect_runs++;
 
-
     /* Snag a block big enough for everything */
     total_size = pad_pool_size(interp, pool);
     alloc_new_block(interp, mem_pools, total_size, pool, "inside compact");
@@ -506,8 +505,8 @@
             (size_t)new_block->start);
 
     /* How much is free. That's the total size minus the amount we used */
-    new_block->free = new_block->size - (new_block->top - new_block->start);
-    mem_pools->memory_collected += (new_block->top - new_block->start);
+    new_block->free = new_block->size - (cur_spot - new_block->start);
+    mem_pools->memory_collected +=      (cur_spot - new_block->start);
 
     free_old_mem_blocks(interp, mem_pools, pool, new_block, total_size);
 
@@ -552,7 +551,7 @@
     UINTVAL total_size = 0;
 
     while (cur_block) {
-        total_size += cur_block->size - cur_block->free;
+        total_size += (cur_block->size - cur_block->free);
         cur_block   = cur_block->prev;
     }
 
@@ -612,12 +611,11 @@
         }
 
         /* buffer has already been moved; just change the header */
-        if (PObj_COW_TEST(old_buf) &&
-            (ref_count && *ref_count & Buffer_moved_FLAG)) {
+        if (PObj_COW_TEST(old_buf)
+        && (ref_count && *ref_count & Buffer_moved_FLAG)) {
             /* Find out who else references our data */
             Buffer * const hdr = *((Buffer **)Buffer_bufstart(old_buf));
 
-
             PARROT_ASSERT(PObj_is_COWable_TEST(old_buf));
 
             /* Make sure they know that we own it too */
@@ -630,10 +628,9 @@
             /* And if we're a string, update strstart */
             /* Somewhat of a hack, but if we get per-pool
              * collections, it should help ease the pain */
-            if (PObj_is_string_TEST(old_buf)) {
-                ((STRING *)old_buf)->strstart = (char *)Buffer_bufstart(old_buf) +
-                        offset;
-            }
+            if (PObj_is_string_TEST(old_buf))
+                ((STRING *)old_buf)->strstart =
+                    (char *)Buffer_bufstart(old_buf) + offset;
         }
         else {
             new_pool_ptr = aligned_mem(old_buf, new_pool_ptr);
@@ -644,7 +641,8 @@
             }
 
             /* Copy our memory to the new pool */
-            memcpy(new_pool_ptr, Buffer_bufstart(old_buf), Buffer_buflen(old_buf));
+            memcpy(new_pool_ptr, Buffer_bufstart(old_buf),
+                                 Buffer_buflen(old_buf));
 
             /* If we're COW */
             if (PObj_COW_TEST(old_buf)) {
@@ -666,10 +664,9 @@
 
             Buffer_bufstart(old_buf) = new_pool_ptr;
 
-            if (PObj_is_string_TEST(old_buf)) {
-                ((STRING *)old_buf)->strstart = (char *)Buffer_bufstart(old_buf) +
-                        offset;
-            }
+            if (PObj_is_string_TEST(old_buf))
+                ((STRING *)old_buf)->strstart =
+                     (char *)Buffer_bufstart(old_buf) + offset;
 
             new_pool_ptr += Buffer_buflen(old_buf);
         }
@@ -761,8 +758,8 @@
     else
         mem = (char*)(((unsigned long)(mem + WORD_ALIGN_1)) & WORD_ALIGN_MASK);
 #endif
-    mem += sizeof (void*);
-    mem = (char*)(((unsigned long)(mem + WORD_ALIGN_1)) & WORD_ALIGN_MASK);
+    mem += sizeof (void *);
+    mem  = (char *)(((unsigned long)(mem + WORD_ALIGN_1)) & WORD_ALIGN_MASK);
 
     return mem;
 }
@@ -784,8 +781,9 @@
 aligned_string_size(size_t len)
 {
     ASSERT_ARGS(aligned_string_size)
+
     len += sizeof (void *);
-    len = (len + WORD_ALIGN_1) & WORD_ALIGN_MASK;
+    len  = (len + WORD_ALIGN_1) & WORD_ALIGN_MASK;
     return len;
 }
 

Modified: trunk/src/gc/gc_ms.c
==============================================================================
--- trunk/src/gc/gc_ms.c	Tue Mar 30 07:49:10 2010	(r45311)
+++ trunk/src/gc/gc_ms.c	Tue Mar 30 07:49:13 2010	(r45312)
@@ -493,8 +493,8 @@
 
         /* We've done the mark, now do the sweep. Pass the sweep callback
            function to the PMC pool and all the sized pools. */
-        header_pools_iterate_callback(interp, interp->mem_pools, POOL_BUFFER | POOL_PMC,
-            (void*)&total_free, gc_ms_sweep_cb);
+       header_pools_iterate_callback(interp, interp->mem_pools,
+            POOL_BUFFER | POOL_PMC, (void *)&total_free, gc_ms_sweep_cb);
 
     }
     else {
@@ -834,18 +834,13 @@
     ARGOUT(Buffer *buffer), size_t size)
 {
     ASSERT_ARGS(gc_ms_allocate_buffer_storage)
-    size_t new_size;
-    char *mem;
+    const size_t new_size   = aligned_string_size(size);
+    const char * const mem  = aligned_mem(buffer,
+        (char *)mem_allocate(interp,
+        interp->mem_pools, new_size, interp->mem_pools->memory_pool));
 
-    Buffer_buflen(buffer) = 0;
-    Buffer_bufstart(buffer) = NULL;
-    new_size = aligned_string_size(size);
-    mem = (char *)mem_allocate(interp, interp->mem_pools, new_size,
-        interp->mem_pools->memory_pool);
-    mem = aligned_mem(buffer, mem);
     Buffer_bufstart(buffer) = mem;
-    new_size -= sizeof (void*);
-    Buffer_buflen(buffer) = new_size;
+    Buffer_buflen(buffer)   = new_size - sizeof (void *);
 }
 
 /*
@@ -893,7 +888,7 @@
     &&  (pool->top_block->top  == (char *)Buffer_bufstart(buffer) + old_size)) {
         pool->top_block->free -= needed;
         pool->top_block->top  += needed;
-        Buffer_buflen(buffer) = newsize;
+        Buffer_buflen(buffer)  = newsize;
         return;
     }
 
@@ -954,10 +949,10 @@
 
     new_size = aligned_string_size(size);
     mem      = (char *)mem_allocate(interp, interp->mem_pools, new_size, pool);
-    mem     += sizeof (void*);
+    mem     += sizeof (void *);
 
     Buffer_bufstart(str) = str->strstart = mem;
-    Buffer_buflen(str)   = new_size - sizeof (void*);
+    Buffer_buflen(str)   = new_size - sizeof (void *);
 }
 
 /*
@@ -1004,7 +999,7 @@
     &&  pool->top_block->top  == (char *)Buffer_bufstart(str) + old_size) {
         pool->top_block->free -= needed;
         pool->top_block->top  += needed;
-        Buffer_buflen(str) = new_size - sizeof (void*);
+        Buffer_buflen(str) = new_size - sizeof (void *);
         return;
     }
 
@@ -1025,7 +1020,7 @@
     oldmem             = str->strstart;
     Buffer_bufstart(str) = (void *)mem;
     str->strstart      = mem;
-    Buffer_buflen(str)   = new_size - sizeof (void*);
+    Buffer_buflen(str)   = new_size - sizeof (void *);
 
     /* We shouldn't ever have a 0 from size, but we do. If we can track down
      * those bugs, this can be removed which would make things cheaper */


More information about the parrot-commits mailing list