Changes in / [ebb7b66:843ca9f]
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/heap.cfa
rebb7b66 r843ca9f 1233 1233 // Attempt to reuse existing storage. 1234 1234 HeapManager.Storage.Header * header = headerAddr( oaddr ); 1235 if ( header->kind.fake.alignment & 1 == 1 ) { // old fake header ? 1236 if ( unlikely( (uintptr_t)oaddr % nalign == 0) && // lucky match ? 1237 header->kind.fake.alignment <= nalign && // ok to leave LSB at 1 1238 nalign <= 128 ) { // not too much alignment storage wasted ? 1239 1240 HeapManager.FreeHeader * freeElem; 1241 size_t bsize, oalign; 1242 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 1243 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 1244 1245 if ( size <= odsize && odsize <= size * 2 ) { // allow 50% wasted data storage 1246 headerAddr( oaddr )->kind.fake.alignment = nalign | 1; // update alignment (could be the same) 1247 1248 header->kind.real.blockSize &= -2; // turn off 0 fill 1249 header->kind.real.size = size; // reset allocation size 1250 return oaddr; 1251 } // if 1252 } // if 1253 } else { // no old fake header 1254 if ( nalign == libAlign() ) { // no new fake header needed => try to reuse storage 1255 HeapManager.FreeHeader * freeElem; 1256 size_t bsize, oalign; 1257 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 1258 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 1259 1260 if ( size <= odsize && odsize <= size * 2 ) { // allow 50% wasted data storage 1261 header->kind.real.blockSize &= -2; // turn off 0 fill 1262 header->kind.real.size = size; // reset allocation size 1263 return oaddr; 1264 } // if 1235 if ( unlikely ( ( header->kind.fake.alignment & 1 == 1 && // old fake header ? 1236 (uintptr_t)oaddr % nalign == 0 && // lucky match ? 1237 header->kind.fake.alignment <= nalign && // ok to leave LSB at 1 1238 nalign <= 128 ) // not too much alignment storage wasted ? 1239 || ( header->kind.fake.alignment & 1 != 1 && // old real header ( aligned on libAlign ) ? 1240 nalign == libAlign() ) ) ) { // new alignment also on libAlign 1241 1242 HeapManager.FreeHeader * freeElem; 1243 size_t bsize, oalign; 1244 headers( "resize", oaddr, header, freeElem, bsize, oalign ); 1245 size_t odsize = dataStorage( bsize, oaddr, header ); // data storage available in bucket 1246 1247 if ( size <= odsize && odsize <= size * 2 ) { // allow 50% wasted data storage 1248 headerAddr( oaddr )->kind.fake.alignment = nalign | 1; // update alignment (could be the same) 1249 1250 header->kind.real.blockSize &= -2; // turn off 0 fill 1251 header->kind.real.size = size; // reset allocation size 1252 return oaddr; 1265 1253 } // if 1266 1254 } // if … … 1298 1286 headers( "realloc", oaddr, header, freeElem, bsize, oalign ); 1299 1287 1300 if ( oalign == nalign ) { // <= alignment and new alignment are same 1301 return realloc( oaddr, size ); 1302 } // if 1303 if ( oalign < nalign && (uintptr_t)oaddr % nalign == 0 && oalign > libAlign() ) { // <= alignment and new alignment happens to match, and oaddr has a fake header 1288 // Attempt to reuse existing storage. 1289 if ( unlikely ( ( header->kind.fake.alignment & 1 == 1 && // old fake header ? 1290 (uintptr_t)oaddr % nalign == 0 && // lucky match ? 1291 header->kind.fake.alignment <= nalign && // ok to leave LSB at 1 1292 nalign <= 128 ) // not too much alignment storage wasted ? 1293 || ( header->kind.fake.alignment & 1 != 1 && // old real header ( aligned on libAlign ) ? 1294 nalign == libAlign() ) ) ) { // new alignment also on libAlign 1295 1304 1296 headerAddr( oaddr )->kind.fake.alignment = nalign | 1; // update alignment (could be the same) 1305 1297 return realloc( oaddr, size ); 1298 1306 1299 } // if 1307 1300
Note: See TracChangeset
for help on using the changeset viewer.