From: H. Peter Anvin Date: Tue, 12 Feb 2008 02:35:41 +0000 (-0800) Subject: shuffle: avoid computing block lists that will never converge X-Git-Tag: syslinux-3.62-pre2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8d419fbcb295fcd8ee54cc5c95326a8da9959f80;p=profile%2Fivi%2Fsyslinux.git 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. --- 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