summaryrefslogtreecommitdiffstats
path: root/usr.bin/diff/diffreg.c
diff options
context:
space:
mode:
authormillert <millert@openbsd.org>2003-08-13 20:44:15 +0000
committermillert <millert@openbsd.org>2003-08-13 20:44:15 +0000
commit2a89a2f7650d88bd19f41433f187d504c9e58625 (patch)
tree0e79f30bc26c20a85499df707be13f5605d4f03a /usr.bin/diff/diffreg.c
parentsocks4->socks, since with support both 4 and 5; dtucker@zip.com.au (diff)
downloadwireguard-openbsd-2a89a2f7650d88bd19f41433f187d504c9e58625.tar.xz
wireguard-openbsd-2a89a2f7650d88bd19f41433f187d504c9e58625.zip
Based on what otto@ said on icb. The expensive thing in diff is
newcand() (this is what blows up the memory usage so badly). Instead of counting how many times we go through the loop, count how many times we called newcand(). I renamed loopcount -> numtries since it is no longer the number of loop runs. This fixes espie@'s regression. tedu@ OK
Diffstat (limited to 'usr.bin/diff/diffreg.c')
-rw-r--r--usr.bin/diff/diffreg.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/usr.bin/diff/diffreg.c b/usr.bin/diff/diffreg.c
index daaf6d7747a..b21c4815f3c 100644
--- a/usr.bin/diff/diffreg.c
+++ b/usr.bin/diff/diffreg.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: diffreg.c,v 1.48 2003/08/08 16:09:26 otto Exp $ */
+/* $OpenBSD: diffreg.c,v 1.49 2003/08/13 20:44:15 millert Exp $ */
/*
* Copyright (C) Caldera International Inc. 2001-2002.
@@ -65,7 +65,7 @@
*/
#ifndef lint
-static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.48 2003/08/08 16:09:26 otto Exp $";
+static const char rcsid[] = "$OpenBSD: diffreg.c,v 1.49 2003/08/13 20:44:15 millert Exp $";
#endif /* not lint */
#include <sys/param.h>
@@ -634,7 +634,7 @@ stone(int *a, int n, int *b, int *c)
{
int i, k, y, j, l;
int oldc, tc, oldl;
- u_int loopcount;
+ u_int numtries;
const u_int bound = dflag ? UINT_MAX : max(256, isqrt(n));
@@ -647,9 +647,8 @@ stone(int *a, int n, int *b, int *c)
y = -b[j];
oldl = 0;
oldc = c[0];
- loopcount = 0;
+ numtries = 0;
do {
- loopcount++;
if (y <= clist[oldc].y)
continue;
l = search(c, k, y);
@@ -662,12 +661,13 @@ stone(int *a, int n, int *b, int *c)
c[l] = newcand(i, y, oldc);
oldc = tc;
oldl = l;
+ numtries++;
} else {
c[l] = newcand(i, y, oldc);
k++;
break;
}
- } while ((y = b[++j]) > 0 && loopcount < bound);
+ } while ((y = b[++j]) > 0 && numtries < bound);
}
return (k);
}