Commit 5fd8c71f3467e64bad0e44f475dd4700c51a3d6f

Authored by Georg Hopp
1 parent a3b0c581

omit not neccessary extra find

Showing 1 changed file with 3 additions and 21 deletions
@@ -123,20 +123,6 @@ _memSegmentCompare(const void * a, const void * b) @@ -123,20 +123,6 @@ _memSegmentCompare(const void * a, const void * b)
123 } 123 }
124 124
125 /** 125 /**
126 - * find element in tree  
127 - */  
128 -static  
129 -struct memSegment *  
130 -findElement(struct memSegment * tree, size_t size)  
131 -{  
132 - int found;  
133 -  
134 - TR_TREE_FIND(tree, &size, found, _memSegmentFindCompare);  
135 -  
136 - return found == 0 ? tree : NULL;  
137 -}  
138 -  
139 -/**  
140 * insert element in tree 126 * insert element in tree
141 */ 127 */
142 static 128 static
@@ -250,7 +236,7 @@ insertElement(struct memSegment ** tree, struct memSegment * element) @@ -250,7 +236,7 @@ insertElement(struct memSegment ** tree, struct memSegment * element)
250 236
251 static 237 static
252 struct memSegment * 238 struct memSegment *
253 -deleteElement(struct memSegment ** tree, struct memSegment * element) 239 +deleteElement(struct memSegment ** tree, size_t size)
254 { 240 {
255 struct memSegment * node = *tree; 241 struct memSegment * node = *tree;
256 struct memSegment * del_node; 242 struct memSegment * del_node;
@@ -259,7 +245,7 @@ deleteElement(struct memSegment ** tree, struct memSegment * element) @@ -259,7 +245,7 @@ deleteElement(struct memSegment ** tree, struct memSegment * element)
259 int found; 245 int found;
260 246
261 // find the relevant node and it's parent 247 // find the relevant node and it's parent
262 - TR_TREE_FIND(node, element, found, _memSegmentCompare); 248 + TR_TREE_FIND(node, &size, found, _memSegmentFindCompare);
263 249
264 //while (node) { 250 //while (node) {
265 if (found != 0) { 251 if (found != 0) {
@@ -530,7 +516,6 @@ post(struct memSegment * tree, void (*cb)(struct memSegment *, int)) @@ -530,7 +516,6 @@ post(struct memSegment * tree, void (*cb)(struct memSegment *, int))
530 } 516 }
531 } 517 }
532 518
533 -static  
534 struct memSegment * segments = NULL; 519 struct memSegment * segments = NULL;
535 520
536 static 521 static
@@ -612,14 +597,11 @@ TR_malloc(size_t size) @@ -612,14 +597,11 @@ TR_malloc(size_t size)
612 } 597 }
613 598
614 #ifdef MEM_OPT 599 #ifdef MEM_OPT
615 - seg = findElement(segments, size); 600 + seg = deleteElement(&segments, size);
616 #endif 601 #endif
617 602
618 if (NULL == seg) { 603 if (NULL == seg) {
619 seg = newElement(size); 604 seg = newElement(size);
620 - } else {  
621 - // remove the found one from the tree as we use it now.  
622 - seg = deleteElement(&segments, seg);  
623 } 605 }
624 606
625 return seg->ptr; 607 return seg->ptr;
Please register or login to post a comment