From 8d419fbcb295fcd8ee54cc5c95326a8da9959f80 Mon Sep 17 00:00:00 2001 From: "H. Peter Anvin" Date: Mon, 11 Feb 2008 18:35:41 -0800 Subject: [PATCH] shuffle: avoid computing block lists that will never converge It is safe to assume that the number of moves will never decrease as the reserved memory space increases; thus, no need to do individual increments; skip ahead. --- com32/lib/syslinux/shuffle.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/com32/lib/syslinux/shuffle.c b/com32/lib/syslinux/shuffle.c index 3393f2a..dcb8d31 100644 --- a/com32/lib/syslinux/shuffle.c +++ b/com32/lib/syslinux/shuffle.c @@ -64,7 +64,7 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, struct syslinux_memmap *rxmap = NULL, *ml; struct shuffle_descriptor *dp, *dbuf; int np, nb, rv = -1; - int desc_blocks; + int desc_blocks, need_blocks; addr_t desczone, descfree, descaddr, descoffs; int nmoves, nzero; struct shuffle_descriptor primaries[2]; @@ -87,8 +87,8 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, dprintf("desczone = 0x%08x, descfree = 0x%08x\n", desczone, descfree); - for (desc_blocks = (nzero+DESC_BLOCK_SIZE)/(DESC_BLOCK_SIZE-1) ; ; - desc_blocks++) { + desc_blocks = (nzero+DESC_BLOCK_SIZE)/(DESC_BLOCK_SIZE-1); + for (;;) { addr_t descmem = desc_blocks* sizeof(struct shuffle_descriptor)*DESC_BLOCK_SIZE; @@ -110,8 +110,12 @@ int syslinux_prepare_shuffle(struct syslinux_movelist *fraglist, for (mp = moves; mp; mp = mp->next) nmoves++; - if ((nmoves+nzero) <= desc_blocks*(DESC_BLOCK_SIZE-1)) + need_blocks = (nmoves+nzero)/(DESC_BLOCK_SIZE-1); + + if (desc_blocks >= need_blocks) break; /* Sufficient memory, yay */ + + desc_blocks = need_blocks; /* Try again... */ } #if DEBUG -- 2.7.4