Browse Source

omit not neccessary extra find

1.0.2
Georg Hopp 12 years ago
parent
commit
5fd8c71f34
  1. 24
      src/memory.c

24
src/memory.c

@ -122,20 +122,6 @@ _memSegmentCompare(const void * a, const void * b)
return _a < _b ? -1 : _a > _b ? 1 : 0; return _a < _b ? -1 : _a > _b ? 1 : 0;
} }
/**
* find element in tree
*/
static
struct memSegment *
findElement(struct memSegment * tree, size_t size)
{
int found;
TR_TREE_FIND(tree, &size, found, _memSegmentFindCompare);
return found == 0 ? tree : NULL;
}
/** /**
* insert element in tree * insert element in tree
*/ */
@ -250,7 +236,7 @@ insertElement(struct memSegment ** tree, struct memSegment * element)
static static
struct memSegment * struct memSegment *
deleteElement(struct memSegment ** tree, struct memSegment * element)
deleteElement(struct memSegment ** tree, size_t size)
{ {
struct memSegment * node = *tree; struct memSegment * node = *tree;
struct memSegment * del_node; struct memSegment * del_node;
@ -259,7 +245,7 @@ deleteElement(struct memSegment ** tree, struct memSegment * element)
int found; int found;
// find the relevant node and it's parent // find the relevant node and it's parent
TR_TREE_FIND(node, element, found, _memSegmentCompare);
TR_TREE_FIND(node, &size, found, _memSegmentFindCompare);
//while (node) { //while (node) {
if (found != 0) { if (found != 0) {
@ -530,7 +516,6 @@ post(struct memSegment * tree, void (*cb)(struct memSegment *, int))
} }
} }
static
struct memSegment * segments = NULL; struct memSegment * segments = NULL;
static static
@ -612,14 +597,11 @@ TR_malloc(size_t size)
} }
#ifdef MEM_OPT #ifdef MEM_OPT
seg = findElement(segments, size);
seg = deleteElement(&segments, size);
#endif #endif
if (NULL == seg) { if (NULL == seg) {
seg = newElement(size); seg = newElement(size);
} else {
// remove the found one from the tree as we use it now.
seg = deleteElement(&segments, seg);
} }
return seg->ptr; return seg->ptr;

Loading…
Cancel
Save