Kaynağa Gözat

Improved remove_block().

Ioannis Koutras 13 yıl önce
ebeveyn
işleme
5151fa4468
1 değiştirilmiş dosya ile 9 ekleme ve 10 silme
  1. 9 10
      block_header.c

+ 9 - 10
block_header.c

@@ -39,21 +39,20 @@ void * get_previous(void *ptr) {
 }
 
 void remove_block(void *block, void *starting_node) {
+
     void *current_node, *previous_node;
 
-    // If the block to be removed is the head of the list, then just point
-    // the next block as head.
-    if(current_node == starting_node) {
-        starting_node = get_next(block);
-        // Else traverse through the list until the memory block is found.
-    } else {
-        for(current_node = starting_node; current_node != NULL; 
-                current_node = get_next(current_node)) {
-            if(current_node == block) {
+    for(current_node = starting_node; current_node != NULL; 
+            current_node = get_next(current_node)) {
+        if(current_node == block) {
+            if(current_node == starting_node) {
+                starting_node = get_next(block);
+            } else {
                 set_next(previous_node, get_next(block));
             }
-            previous_node = current_node;
+            break;
         }
+        previous_node = current_node;
     }
 }