Skip to content
Snippets Groups Projects
Commit fd4ff9dd authored by Kostyantyn Vorobyov's avatar Kostyantyn Vorobyov
Browse files

Rebase

parent 04a524ca
No related branches found
No related tags found
No related merge requests found
...@@ -355,34 +355,19 @@ static struct _block * get_cont (void * ptr) { ...@@ -355,34 +355,19 @@ static struct _block * get_cont (void * ptr) {
struct bittree * tmp = __root; struct bittree * tmp = __root;
if(__root == NULL || ptr == NULL) return NULL; if(__root == NULL || ptr == NULL) return NULL;
struct bittree * t [WORDBITS]; struct bittree * other_choice = NULL;
short ind = -1;
while(1) { while(1) {
if(tmp->is_leaf) { if(tmp->is_leaf) {
/* tmp cannot contain ptr because its begin addr is higher */ /* tmp cannot contain ptr because its begin addr is higher */
if(tmp->addr > (size_t)ptr) { if(tmp->addr > (size_t)ptr) return NULL;
if(ind == -1)
return NULL;
else {
tmp = t[ind];
ind--;
continue;
}
}
/* tmp->addr <= ptr, tmp may contain ptr /* tmp->addr <= ptr, tmp may contain ptr
ptr is contained if tmp is large enough (begin addr + size) */ ptr is contained if tmp is large enough (begin addr + size) */
else if((size_t)ptr < tmp->leaf->size + tmp->addr else if((size_t)ptr < tmp->leaf->size + tmp->addr
|| (tmp->leaf->size == 0 && (size_t)ptr == tmp->leaf->ptr)) || (tmp->leaf->size == 0 && (size_t)ptr == tmp->leaf->ptr))
return tmp->leaf; return tmp->leaf;
/* tmp->addr <= ptr, but tmp->addr is not large enough */ /* tmp->addr <= ptr, but tmp->addr is not large enough */
else if (ind == -1) else return NULL;
return NULL;
else {
tmp = t[ind];
ind--;
continue;
}
} }
assert(tmp->left != NULL && tmp->right != NULL); assert(tmp->left != NULL && tmp->right != NULL);
...@@ -390,19 +375,18 @@ static struct _block * get_cont (void * ptr) { ...@@ -390,19 +375,18 @@ static struct _block * get_cont (void * ptr) {
/* the right child has the highest address, so we test it first */ /* the right child has the highest address, so we test it first */
if(((size_t)tmp->right->addr & tmp->right->mask) if(((size_t)tmp->right->addr & tmp->right->mask)
<= ((size_t)ptr & tmp->right->mask)) { <= ((size_t)ptr & tmp->right->mask)) {
ind++; other_choice = tmp->left;
t[ind] = tmp->left;
tmp = tmp->right; tmp = tmp->right;
} }
else if(((size_t)tmp->left->addr & tmp->left->mask) else if(((size_t)tmp->left->addr & tmp->left->mask)
<= ((size_t)ptr & tmp->left->mask)) <= ((size_t)ptr & tmp->left->mask))
tmp = tmp->left; tmp = tmp->left;
else { else {
if(ind == -1) if(other_choice == NULL)
return NULL; return NULL;
else { else {
tmp = t[ind]; tmp = other_choice;
ind--; other_choice = NULL;
} }
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment