Commit a86d820c authored by Yoni Fogel's avatar Yoni Fogel

Addresses #918

Allocates room for at least 4 elements every time we convert from tree
to array (and vice versa).

git-svn-id: file:///svn/tokudb@4586 c7de825b-a66e-492c-adef-691d508d4ae1
parent da523d46
...@@ -199,6 +199,7 @@ static int omt_convert_to_tree(OMT omt) { ...@@ -199,6 +199,7 @@ static int omt_convert_to_tree(OMT omt) {
if (!omt->is_array) return 0; if (!omt->is_array) return 0;
u_int32_t num_nodes = omt_size(omt); u_int32_t num_nodes = omt_size(omt);
u_int32_t new_size = num_nodes*2; u_int32_t new_size = num_nodes*2;
new_size = new_size < 4 ? 4 : new_size;
OMT_NODE MALLOC_N(new_size, new_nodes); OMT_NODE MALLOC_N(new_size, new_nodes);
if (new_nodes==NULL) return errno; if (new_nodes==NULL) return errno;
...@@ -206,7 +207,7 @@ static int omt_convert_to_tree(OMT omt) { ...@@ -206,7 +207,7 @@ static int omt_convert_to_tree(OMT omt) {
OMTVALUE *tmp_values = values + omt->i.a.start_idx; OMTVALUE *tmp_values = values + omt->i.a.start_idx;
omt->is_array = FALSE; omt->is_array = FALSE;
omt->i.t.nodes = new_nodes; omt->i.t.nodes = new_nodes;
omt->capacity = new_size; omt->capacity = new_size;
omt->i.t.free_idx = 0; /* Allocating from mempool starts over. */ omt->i.t.free_idx = 0; /* Allocating from mempool starts over. */
omt->i.t.root = NODE_NULL; omt->i.t.root = NODE_NULL;
rebuild_from_sorted_array(omt, &omt->i.t.root, tmp_values, num_nodes); rebuild_from_sorted_array(omt, &omt->i.t.root, tmp_values, num_nodes);
...@@ -217,13 +218,15 @@ static int omt_convert_to_tree(OMT omt) { ...@@ -217,13 +218,15 @@ static int omt_convert_to_tree(OMT omt) {
static int omt_convert_to_array(OMT omt) { static int omt_convert_to_array(OMT omt) {
if (omt->is_array) return 0; if (omt->is_array) return 0;
u_int32_t num_values = omt_size(omt); u_int32_t num_values = omt_size(omt);
u_int32_t capacity = 2*num_values; u_int32_t new_size = 2*num_values;
OMTVALUE *MALLOC_N(capacity, tmp_values); new_size = new_size < 4 ? 4 : new_size;
OMTVALUE *MALLOC_N(new_size, tmp_values);
if (tmp_values==NULL) return errno; if (tmp_values==NULL) return errno;
fill_array_with_subtree_values(omt, tmp_values, omt->i.t.root); fill_array_with_subtree_values(omt, tmp_values, omt->i.t.root);
toku_free(omt->i.t.nodes); toku_free(omt->i.t.nodes);
omt->is_array = TRUE; omt->is_array = TRUE;
omt->capacity = capacity; omt->capacity = new_size;
omt->i.a.num_values = num_values; omt->i.a.num_values = num_values;
omt->i.a.values = tmp_values; omt->i.a.values = tmp_values;
omt->i.a.start_idx = 0; omt->i.a.start_idx = 0;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment