manage itermonarr; it used to be allocated and freed every time the monster movement loop ran; now, keep it around most of the time */
| 4468 | /* manage itermonarr; it used to be allocated and freed every time the |
| 4469 | monster movement loop ran; now, keep it around most of the time */ |
| 4470 | void |
| 4471 | alloc_itermonarr(unsigned count) |
| 4472 | { |
| 4473 | /* if count is 0 or bigger than itermonsiz or much smaller than |
| 4474 | itermonsiz, release itermonarr (and reset itermonsiz to 0) */ |
| 4475 | if (!count || count > itermonsiz || count + 40 < itermonsiz) { |
| 4476 | if (itermonarr) |
| 4477 | free((genericptr_t) itermonarr), itermonarr = NULL; |
| 4478 | itermonsiz = 0; |
| 4479 | } |
| 4480 | /* when count is more than itermonsiz (including when that just |
| 4481 | got reset to 0), allocate a new instance of itermonarr; |
| 4482 | implies that count is greater than 0 */ |
| 4483 | if (count > itermonsiz) { |
| 4484 | /* overallocate to reduce free/alloc-again thrashing when the |
| 4485 | number of monsters varies from turn to turn */ |
| 4486 | itermonsiz = count + 20; |
| 4487 | itermonarr = (struct monst **) alloc( |
| 4488 | itermonsiz * sizeof (struct monst *)); |
| 4489 | } |
| 4490 | } |
| 4491 | |
| 4492 | /* Iterate all monsters on the level, even dead or off-map ones, calling |
| 4493 | bfunc() for each monster. If bfunc() returns TRUE, stop iterating. |
no test coverage detected