Browse Source

Simplified some checks while coalescing

Ioannis Koutras 12 years ago
parent
commit
3885778a39
2 changed files with 6 additions and 13 deletions
  1. 2 6
      src/freelist/block_header_funcs.c
  2. 4 7
      src/freelist/coalesce.c

+ 2 - 6
src/freelist/block_header_funcs.c

@@ -1,5 +1,5 @@
 /*
- *   Copyright 2011 Institute of Communication and Computer Systems (ICCS) 
+ *   Copyright Institute of Communication and Computer Systems (ICCS) 
  *
  *   Licensed under the Apache License, Version 2.0 (the "License");
  *   you may not use this file except in compliance with the License.
@@ -84,11 +84,7 @@ void mark_free(freelist_rb_t *raw_block, block_header_t *ptr) {
     }    
 }
 
-bool is_free(block_header_t * ptr) {
-    if(ptr == NULL) {
-        return false;
-    }
-
+bool is_free(block_header_t *ptr) {
     if(ptr->size & (size_t) 1) {
         return false;
     } else {

+ 4 - 7
src/freelist/coalesce.c

@@ -43,12 +43,8 @@ void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
     /* Find out the sizes of all possible combinations */
 
     /* Current + Next */
-    if(next_block != NULL) {
-        if(is_free(next_block) == true) {
-                current_next_size = size + get_size(next_block) + HEADER_SIZE;
-        } else {
-            current_next_size = (size_t) -1; /* SIZE_MAX */
-        }
+    if(next_block != NULL && is_free(next_block) == true) {
+        current_next_size = size + get_size(next_block) + HEADER_SIZE;
     } else {
         current_next_size = (size_t) -1; /* SIZE_MAX */
     }
@@ -61,7 +57,8 @@ void coalesce(freelist_rb_t *raw_block, block_header_t *ptr) {
     }
 
     /* Previous + Current + Next */
-    if(is_previous_free(ptr) == true && is_free(next_block) == true) {
+    if(is_previous_free(ptr) == true && next_block != NULL &&
+            is_free(next_block) == true) {
         three_blocks_size = get_previous_size(ptr) + size +
             get_size(next_block) + 2 * HEADER_SIZE;
     } else {