Bump the initial record buffer size to 1MB and allow it to grow to 8MB,
if needed and record count is within bounds (<MAXNUM), rather than sorting the input by 64KB chunks. This cuts the number of needed temporary files considerably (and improves performance, too). Slighly adjust some #defines, mostly to power of 2 values. This addresses bin/12673 and bin/12614, as well as complains from other people.
This commit is contained in:
parent
c98f5d554b
commit
231887cbb4
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fsort.c,v 1.17 2001/02/20 18:33:09 jdolecek Exp $ */
|
||||
/* $NetBSD: fsort.c,v 1.18 2001/05/14 21:45:19 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
@ -47,7 +47,7 @@
|
||||
#include "fsort.h"
|
||||
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: fsort.c,v 1.17 2001/02/20 18:33:09 jdolecek Exp $");
|
||||
__RCSID("$NetBSD: fsort.c,v 1.18 2001/05/14 21:45:19 jdolecek Exp $");
|
||||
__SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93");
|
||||
#endif /* not lint */
|
||||
|
||||
@ -56,7 +56,7 @@ __SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93");
|
||||
|
||||
static const u_char **keylist = 0;
|
||||
u_char *buffer = 0, *linebuf = 0;
|
||||
size_t bufsize = DEFLLEN;
|
||||
size_t bufsize = DEFBUFSIZE;
|
||||
size_t linebuf_size;
|
||||
struct tempfile fstack[MAXFCT];
|
||||
extern char *toutpath;
|
||||
@ -145,7 +145,8 @@ fsort(binno, depth, top, filelist, nfiles, outfp, ftbl)
|
||||
SALIGN(crec->length) + sizeof(TRECHEADER));
|
||||
}
|
||||
|
||||
if (c == BUFFEND && nelem < min(9, MAXNUM)) {
|
||||
if (c == BUFFEND && nelem < MAXNUM
|
||||
&& bufsize < MAXBUFSIZE) {
|
||||
const u_char **keyp;
|
||||
u_char *oldb = buffer;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: fsort.h,v 1.8 2001/02/19 20:50:17 jdolecek Exp $ */
|
||||
/* $NetBSD: fsort.h,v 1.9 2001/05/14 21:45:20 jdolecek Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1993
|
||||
@ -39,11 +39,19 @@
|
||||
*/
|
||||
|
||||
#define BUFSIZE (1<<20)
|
||||
#define MAXNUM (BUFSIZE/10) /* low guess at average record size */
|
||||
#define MAXNUM 131072 /* low guess at average record count */
|
||||
#define BUFFEND (EOF-2)
|
||||
#define MAXFCT 1000
|
||||
#define DEFLLEN 65536
|
||||
|
||||
/*
|
||||
* Default (initial) and maximum size of record buffer for fsort().
|
||||
* Note that no more than MAXNUM records are stored in the buffer,
|
||||
* even if the buffer is not full yet.
|
||||
*/
|
||||
#define DEFBUFSIZE (1 << 20) /* 1MB */
|
||||
#define MAXBUFSIZE (8 << 20) /* 10 MB */
|
||||
|
||||
/*
|
||||
* Number of files merge() can merge in one pass.
|
||||
* This should be power of two so that it's possible to use this value
|
||||
|
Loading…
Reference in New Issue
Block a user