Showing
1 changed file
with
3 additions
and
21 deletions
... | ... | @@ -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 | 126 | * insert element in tree |
141 | 127 | */ |
142 | 128 | static |
... | ... | @@ -250,7 +236,7 @@ insertElement(struct memSegment ** tree, struct memSegment * element) |
250 | 236 | |
251 | 237 | static |
252 | 238 | struct memSegment * |
253 | -deleteElement(struct memSegment ** tree, struct memSegment * element) | |
239 | +deleteElement(struct memSegment ** tree, size_t size) | |
254 | 240 | { |
255 | 241 | struct memSegment * node = *tree; |
256 | 242 | struct memSegment * del_node; |
... | ... | @@ -259,7 +245,7 @@ deleteElement(struct memSegment ** tree, struct memSegment * element) |
259 | 245 | int found; |
260 | 246 | |
261 | 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 | 250 | //while (node) { |
265 | 251 | if (found != 0) { |
... | ... | @@ -530,7 +516,6 @@ post(struct memSegment * tree, void (*cb)(struct memSegment *, int)) |
530 | 516 | } |
531 | 517 | } |
532 | 518 | |
533 | -static | |
534 | 519 | struct memSegment * segments = NULL; |
535 | 520 | |
536 | 521 | static |
... | ... | @@ -612,14 +597,11 @@ TR_malloc(size_t size) |
612 | 597 | } |
613 | 598 | |
614 | 599 | #ifdef MEM_OPT |
615 | - seg = findElement(segments, size); | |
600 | + seg = deleteElement(&segments, size); | |
616 | 601 | #endif |
617 | 602 | |
618 | 603 | if (NULL == seg) { |
619 | 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 | 607 | return seg->ptr; | ... | ... |
Please
register
or
login
to post a comment