Mercurial > emacs
comparison src/alloc.c @ 21379:1701bf5b9dec
(gc_sweep): Avoid using two loop variables counting the
same thing.
| author | Andreas Schwab <schwab@suse.de> |
|---|---|
| date | Mon, 06 Apr 1998 09:04:23 +0000 |
| parents | dc2cbd40703c |
| children | fa9ff387d260 |
comparison
equal
deleted
inserted
replaced
| 21378:e77ae6b31cb3 | 21379:1701bf5b9dec |
|---|---|
| 2375 register int i; | 2375 register int i; |
| 2376 int this_free = 0; | 2376 int this_free = 0; |
| 2377 for (i = 0; i < lim; i++) | 2377 for (i = 0; i < lim; i++) |
| 2378 if (!XMARKBIT (cblk->conses[i].car)) | 2378 if (!XMARKBIT (cblk->conses[i].car)) |
| 2379 { | 2379 { |
| 2380 num_free++; | |
| 2381 this_free++; | 2380 this_free++; |
| 2382 *(struct Lisp_Cons **)&cblk->conses[i].cdr = cons_free_list; | 2381 *(struct Lisp_Cons **)&cblk->conses[i].cdr = cons_free_list; |
| 2383 cons_free_list = &cblk->conses[i]; | 2382 cons_free_list = &cblk->conses[i]; |
| 2384 } | 2383 } |
| 2385 else | 2384 else |
| 2389 } | 2388 } |
| 2390 lim = CONS_BLOCK_SIZE; | 2389 lim = CONS_BLOCK_SIZE; |
| 2391 /* If this block contains only free conses and we have already | 2390 /* If this block contains only free conses and we have already |
| 2392 seen more than two blocks worth of free conses then deallocate | 2391 seen more than two blocks worth of free conses then deallocate |
| 2393 this block. */ | 2392 this block. */ |
| 2394 if (this_free == CONS_BLOCK_SIZE && num_free > 2*CONS_BLOCK_SIZE) | 2393 if (this_free == CONS_BLOCK_SIZE && num_free > CONS_BLOCK_SIZE) |
| 2395 { | 2394 { |
| 2396 num_free -= CONS_BLOCK_SIZE; | |
| 2397 *cprev = cblk->next; | 2395 *cprev = cblk->next; |
| 2398 /* Unhook from the free list. */ | 2396 /* Unhook from the free list. */ |
| 2399 cons_free_list = *(struct Lisp_Cons **) &cblk->conses[0].cdr; | 2397 cons_free_list = *(struct Lisp_Cons **) &cblk->conses[0].cdr; |
| 2400 xfree (cblk); | 2398 xfree (cblk); |
| 2401 } | 2399 } |
| 2402 else | 2400 else |
| 2403 cprev = &cblk->next; | 2401 { |
| 2402 num_free += this_free; | |
| 2403 cprev = &cblk->next; | |
| 2404 } | |
| 2404 } | 2405 } |
| 2405 total_conses = num_used; | 2406 total_conses = num_used; |
| 2406 total_free_conses = num_free; | 2407 total_free_conses = num_free; |
| 2407 } | 2408 } |
| 2408 | 2409 |
| 2421 register int i; | 2422 register int i; |
| 2422 int this_free = 0; | 2423 int this_free = 0; |
| 2423 for (i = 0; i < lim; i++) | 2424 for (i = 0; i < lim; i++) |
| 2424 if (!XMARKBIT (fblk->floats[i].type)) | 2425 if (!XMARKBIT (fblk->floats[i].type)) |
| 2425 { | 2426 { |
| 2426 num_free++; | |
| 2427 this_free++; | 2427 this_free++; |
| 2428 *(struct Lisp_Float **)&fblk->floats[i].data = float_free_list; | 2428 *(struct Lisp_Float **)&fblk->floats[i].data = float_free_list; |
| 2429 float_free_list = &fblk->floats[i]; | 2429 float_free_list = &fblk->floats[i]; |
| 2430 } | 2430 } |
| 2431 else | 2431 else |
| 2435 } | 2435 } |
| 2436 lim = FLOAT_BLOCK_SIZE; | 2436 lim = FLOAT_BLOCK_SIZE; |
| 2437 /* If this block contains only free floats and we have already | 2437 /* If this block contains only free floats and we have already |
| 2438 seen more than two blocks worth of free floats then deallocate | 2438 seen more than two blocks worth of free floats then deallocate |
| 2439 this block. */ | 2439 this block. */ |
| 2440 if (this_free == FLOAT_BLOCK_SIZE && num_free > 2*FLOAT_BLOCK_SIZE) | 2440 if (this_free == FLOAT_BLOCK_SIZE && num_free > FLOAT_BLOCK_SIZE) |
| 2441 { | 2441 { |
| 2442 num_free -= FLOAT_BLOCK_SIZE; | |
| 2443 *fprev = fblk->next; | 2442 *fprev = fblk->next; |
| 2444 /* Unhook from the free list. */ | 2443 /* Unhook from the free list. */ |
| 2445 float_free_list = *(struct Lisp_Float **) &fblk->floats[0].data; | 2444 float_free_list = *(struct Lisp_Float **) &fblk->floats[0].data; |
| 2446 xfree (fblk); | 2445 xfree (fblk); |
| 2447 } | 2446 } |
| 2448 else | 2447 else |
| 2449 fprev = &fblk->next; | 2448 { |
| 2449 num_free += this_free; | |
| 2450 fprev = &fblk->next; | |
| 2451 } | |
| 2450 } | 2452 } |
| 2451 total_floats = num_used; | 2453 total_floats = num_used; |
| 2452 total_free_floats = num_free; | 2454 total_free_floats = num_free; |
| 2453 } | 2455 } |
| 2454 #endif /* LISP_FLOAT_TYPE */ | 2456 #endif /* LISP_FLOAT_TYPE */ |
| 2472 { | 2474 { |
| 2473 if (! XMARKBIT (iblk->intervals[i].plist)) | 2475 if (! XMARKBIT (iblk->intervals[i].plist)) |
| 2474 { | 2476 { |
| 2475 iblk->intervals[i].parent = interval_free_list; | 2477 iblk->intervals[i].parent = interval_free_list; |
| 2476 interval_free_list = &iblk->intervals[i]; | 2478 interval_free_list = &iblk->intervals[i]; |
| 2477 num_free++; | |
| 2478 this_free++; | 2479 this_free++; |
| 2479 } | 2480 } |
| 2480 else | 2481 else |
| 2481 { | 2482 { |
| 2482 num_used++; | 2483 num_used++; |
| 2485 } | 2486 } |
| 2486 lim = INTERVAL_BLOCK_SIZE; | 2487 lim = INTERVAL_BLOCK_SIZE; |
| 2487 /* If this block contains only free intervals and we have already | 2488 /* If this block contains only free intervals and we have already |
| 2488 seen more than two blocks worth of free intervals then | 2489 seen more than two blocks worth of free intervals then |
| 2489 deallocate this block. */ | 2490 deallocate this block. */ |
| 2490 if (this_free == INTERVAL_BLOCK_SIZE | 2491 if (this_free == INTERVAL_BLOCK_SIZE && num_free > INTERVAL_BLOCK_SIZE) |
| 2491 && num_free > 2*INTERVAL_BLOCK_SIZE) | |
| 2492 { | 2492 { |
| 2493 num_free -= INTERVAL_BLOCK_SIZE; | |
| 2494 *iprev = iblk->next; | 2493 *iprev = iblk->next; |
| 2495 /* Unhook from the free list. */ | 2494 /* Unhook from the free list. */ |
| 2496 interval_free_list = iblk->intervals[0].parent; | 2495 interval_free_list = iblk->intervals[0].parent; |
| 2497 xfree (iblk); | 2496 xfree (iblk); |
| 2498 } | 2497 } |
| 2499 else | 2498 else |
| 2500 iprev = &iblk->next; | 2499 { |
| 2500 num_free += this_free; | |
| 2501 iprev = &iblk->next; | |
| 2502 } | |
| 2501 } | 2503 } |
| 2502 total_intervals = num_used; | 2504 total_intervals = num_used; |
| 2503 total_free_intervals = num_free; | 2505 total_free_intervals = num_free; |
| 2504 } | 2506 } |
| 2505 #endif /* USE_TEXT_PROPERTIES */ | 2507 #endif /* USE_TEXT_PROPERTIES */ |
| 2520 for (i = 0; i < lim; i++) | 2522 for (i = 0; i < lim; i++) |
| 2521 if (!XMARKBIT (sblk->symbols[i].plist)) | 2523 if (!XMARKBIT (sblk->symbols[i].plist)) |
| 2522 { | 2524 { |
| 2523 *(struct Lisp_Symbol **)&sblk->symbols[i].value = symbol_free_list; | 2525 *(struct Lisp_Symbol **)&sblk->symbols[i].value = symbol_free_list; |
| 2524 symbol_free_list = &sblk->symbols[i]; | 2526 symbol_free_list = &sblk->symbols[i]; |
| 2525 num_free++; | |
| 2526 this_free++; | 2527 this_free++; |
| 2527 } | 2528 } |
| 2528 else | 2529 else |
| 2529 { | 2530 { |
| 2530 num_used++; | 2531 num_used++; |
| 2534 } | 2535 } |
| 2535 lim = SYMBOL_BLOCK_SIZE; | 2536 lim = SYMBOL_BLOCK_SIZE; |
| 2536 /* If this block contains only free symbols and we have already | 2537 /* If this block contains only free symbols and we have already |
| 2537 seen more than two blocks worth of free symbols then deallocate | 2538 seen more than two blocks worth of free symbols then deallocate |
| 2538 this block. */ | 2539 this block. */ |
| 2539 if (this_free == SYMBOL_BLOCK_SIZE && num_free > 2*SYMBOL_BLOCK_SIZE) | 2540 if (this_free == SYMBOL_BLOCK_SIZE && num_free > SYMBOL_BLOCK_SIZE) |
| 2540 { | 2541 { |
| 2541 num_free -= SYMBOL_BLOCK_SIZE; | |
| 2542 *sprev = sblk->next; | 2542 *sprev = sblk->next; |
| 2543 /* Unhook from the free list. */ | 2543 /* Unhook from the free list. */ |
| 2544 symbol_free_list = *(struct Lisp_Symbol **)&sblk->symbols[0].value; | 2544 symbol_free_list = *(struct Lisp_Symbol **)&sblk->symbols[0].value; |
| 2545 xfree (sblk); | 2545 xfree (sblk); |
| 2546 } | 2546 } |
| 2547 else | 2547 else |
| 2548 sprev = &sblk->next; | 2548 { |
| 2549 num_free += this_free; | |
| 2550 sprev = &sblk->next; | |
| 2551 } | |
| 2549 } | 2552 } |
| 2550 total_symbols = num_used; | 2553 total_symbols = num_used; |
| 2551 total_free_symbols = num_free; | 2554 total_free_symbols = num_free; |
| 2552 } | 2555 } |
| 2553 | 2556 |
| 2606 We could leave the type alone, since nobody checks it, | 2609 We could leave the type alone, since nobody checks it, |
| 2607 but this might catch bugs faster. */ | 2610 but this might catch bugs faster. */ |
| 2608 mblk->markers[i].u_marker.type = Lisp_Misc_Free; | 2611 mblk->markers[i].u_marker.type = Lisp_Misc_Free; |
| 2609 mblk->markers[i].u_free.chain = marker_free_list; | 2612 mblk->markers[i].u_free.chain = marker_free_list; |
| 2610 marker_free_list = &mblk->markers[i]; | 2613 marker_free_list = &mblk->markers[i]; |
| 2611 num_free++; | |
| 2612 this_free++; | 2614 this_free++; |
| 2613 } | 2615 } |
| 2614 else | 2616 else |
| 2615 { | 2617 { |
| 2616 num_used++; | 2618 num_used++; |
| 2620 } | 2622 } |
| 2621 lim = MARKER_BLOCK_SIZE; | 2623 lim = MARKER_BLOCK_SIZE; |
| 2622 /* If this block contains only free markers and we have already | 2624 /* If this block contains only free markers and we have already |
| 2623 seen more than two blocks worth of free markers then deallocate | 2625 seen more than two blocks worth of free markers then deallocate |
| 2624 this block. */ | 2626 this block. */ |
| 2625 if (this_free == MARKER_BLOCK_SIZE && num_free > 2*MARKER_BLOCK_SIZE) | 2627 if (this_free == MARKER_BLOCK_SIZE && num_free > MARKER_BLOCK_SIZE) |
| 2626 { | 2628 { |
| 2627 num_free -= MARKER_BLOCK_SIZE; | |
| 2628 *mprev = mblk->next; | 2629 *mprev = mblk->next; |
| 2629 /* Unhook from the free list. */ | 2630 /* Unhook from the free list. */ |
| 2630 marker_free_list = mblk->markers[0].u_free.chain; | 2631 marker_free_list = mblk->markers[0].u_free.chain; |
| 2631 xfree (mblk); | 2632 xfree (mblk); |
| 2632 } | 2633 } |
| 2633 else | 2634 else |
| 2634 mprev = &mblk->next; | 2635 { |
| 2636 num_free += this_free; | |
| 2637 mprev = &mblk->next; | |
| 2638 } | |
| 2635 } | 2639 } |
| 2636 | 2640 |
| 2637 total_markers = num_used; | 2641 total_markers = num_used; |
| 2638 total_free_markers = num_free; | 2642 total_free_markers = num_free; |
| 2639 } | 2643 } |
