aboutsummaryrefslogtreecommitdiffstats
path: root/com32/lib/syslinux/shuffle.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2008-02-11 18:35:41 -0800
committerH. Peter Anvin <hpa@zytor.com>2008-02-11 18:35:41 -0800
commit8d419fbcb295fcd8ee54cc5c95326a8da9959f80 (patch)
tree8938d5ef6054f697fc109222822dd63c3b394d7d /com32/lib/syslinux/shuffle.c
parenta560584d9f38322e3528e772f61fce56774054b4 (diff)
downloadsyslinux-8d419fbcb295fcd8ee54cc5c95326a8da9959f80.tar.gz
syslinux-8d419fbcb295fcd8ee54cc5c95326a8da9959f80.tar.xz
syslinux-8d419fbcb295fcd8ee54cc5c95326a8da9959f80.zip
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.
Diffstat (limited to 'com32/lib/syslinux/shuffle.c')
-rw-r--r--com32/lib/syslinux/shuffle.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/com32/lib/syslinux/shuffle.c b/com32/lib/syslinux/shuffle.c
index 3393f2a8..dcb8d310 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