Commit d8c92a6c115dee26b3e1d3ba2269e00ad79dd8ba

Authored by Georg Hopp
1 parent f61b6275

Optimize memory size calculation

Showing 1 changed file with 4 additions and 9 deletions
@@ -204,16 +204,11 @@ TR_malloc(size_t size) @@ -204,16 +204,11 @@ TR_malloc(size_t size)
204 size = 1 << (MIN_BITS - 1); 204 size = 1 << (MIN_BITS - 1);
205 idx = 0; 205 idx = 0;
206 } else { 206 } else {
207 - size_t mask;  
208 -  
209 - idx = TR_bitwidth(size);  
210 - mask = (1 << (idx + 1)) - 1; 207 + // size-1 to ensure that powers of two will not be
  208 + // changed to the next power of two
  209 + idx = TR_bitwidth(size-1) + 1;
  210 + size = 1 << idx;
211 idx -= (MIN_BITS - 1); 211 idx -= (MIN_BITS - 1);
212 -  
213 - if (size != (size & ~(mask >> 1))) {  
214 - size = (size << 1) & ~mask;  
215 - idx++;  
216 - }  
217 } 212 }
218 } 213 }
219 214
Please register or login to post a comment