Module Name: src Committed By: dsl Date: Sun Aug 16 20:02:04 UTC 2009
Modified Files: src/usr.bin/sort: append.c fsort.c Log Message: 'depth' is used for the number of bytes into the key that the pointers reference, when we want to find the record header put the larger value into 'hdr_off' to avoid any confusion that the code might be changing 'depth'! There is now no need to save the original value as 'odepth' in append.c. All an a vague attempt to make this code slightly readable. To generate a diff of this commit: cvs rdiff -u -r1.16 -r1.17 src/usr.bin/sort/append.c cvs rdiff -u -r1.35 -r1.36 src/usr.bin/sort/fsort.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/sort/append.c diff -u src/usr.bin/sort/append.c:1.16 src/usr.bin/sort/append.c:1.17 --- src/usr.bin/sort/append.c:1.16 Sun Aug 16 19:53:43 2009 +++ src/usr.bin/sort/append.c Sun Aug 16 20:02:04 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: append.c,v 1.16 2009/08/16 19:53:43 dsl Exp $ */ +/* $NetBSD: append.c,v 1.17 2009/08/16 20:02:04 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -64,7 +64,7 @@ #include "sort.h" #ifndef lint -__RCSID("$NetBSD: append.c,v 1.16 2009/08/16 19:53:43 dsl Exp $"); +__RCSID("$NetBSD: append.c,v 1.17 2009/08/16 20:02:04 dsl Exp $"); __SCCSID("@(#)append.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -74,7 +74,7 @@ #define OUTPUT { \ if ((n = cpos - ppos) > 1) { \ for (; ppos < cpos; ++ppos) \ - *ppos -= odepth; \ + *ppos -= depth; \ ppos -= n; \ if (stable_sort) \ sradixsort(ppos, n, wts1, REC_D); \ @@ -95,7 +95,8 @@ struct field *ftbl) { u_char *wts, *wts1; - int n, odepth = depth; + int n; + int hdr_off; const u_char **cpos, **ppos, **lastkey; const u_char *cend, *pend, *start; const struct recheader *crec, *prec; @@ -110,14 +111,14 @@ wts1 = ascii; } lastkey = keylist + nelem; - depth += REC_DATA_OFFSET; + hdr_off = REC_DATA_OFFSET + depth; if (SINGL_FLD && (UNIQUE || wts1 != wts)) { ppos = keylist; - prec = (const RECHEADER *) (*ppos - depth); + prec = (const RECHEADER *) (*ppos - hdr_off); if (UNIQUE) put(prec, fp); for (cpos = &keylist[1]; cpos < lastkey; cpos++) { - crec = (const RECHEADER *) (*cpos - depth); + crec = (const RECHEADER *) (*cpos - hdr_off); if (crec->length == prec->length) { /* * Set pend and cend so that trailing NUL and @@ -150,10 +151,10 @@ if (!UNIQUE) { OUTPUT; } } else if (UNIQUE) { ppos = keylist; - prec = (const RECHEADER *) (*ppos - depth); + prec = (const RECHEADER *) (*ppos - hdr_off); put(prec, fp); for (cpos = &keylist[1]; cpos < lastkey; cpos++) { - crec = (const RECHEADER *) (*cpos - depth); + crec = (const RECHEADER *) (*cpos - hdr_off); if (crec->offset == prec->offset) { /* * Set pend and cend so that trailing NUL and @@ -178,7 +179,7 @@ } } } else for (cpos = keylist; cpos < lastkey; cpos++) { - crec = (const RECHEADER *) (*cpos - depth); + crec = (const RECHEADER *) (*cpos - hdr_off); put(crec, fp); } } Index: src/usr.bin/sort/fsort.c diff -u src/usr.bin/sort/fsort.c:1.35 src/usr.bin/sort/fsort.c:1.36 --- src/usr.bin/sort/fsort.c:1.35 Sun Aug 16 19:53:43 2009 +++ src/usr.bin/sort/fsort.c Sun Aug 16 20:02:04 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: fsort.c,v 1.35 2009/08/16 19:53:43 dsl Exp $ */ +/* $NetBSD: fsort.c,v 1.36 2009/08/16 20:02:04 dsl Exp $ */ /*- * Copyright (c) 2000-2003 The NetBSD Foundation, Inc. @@ -72,7 +72,7 @@ #include "fsort.h" #ifndef lint -__RCSID("$NetBSD: fsort.c,v 1.35 2009/08/16 19:53:43 dsl Exp $"); +__RCSID("$NetBSD: fsort.c,v 1.36 2009/08/16 20:02:04 dsl Exp $"); __SCCSID("@(#)fsort.c 8.1 (Berkeley) 6/6/93"); #endif /* not lint */ @@ -341,15 +341,16 @@ static int histo[256]; int *hp; int c; + int hdr_off; const u_char **an, *t, **aj; const u_char **ak, *r; memset(tsizes, 0, sizeof(tsizes)); - depth += REC_DATA_OFFSET; + hdr_off = REC_DATA_OFFSET + depth; an = &a[n]; for (ak = a; ak < an; ak++) { histo[c = tr[**ak]]++; - tsizes[c] += ((const RECHEADER *) (*ak -= depth))->length; + tsizes[c] += ((const RECHEADER *) (*ak -= hdr_off))->length; } bin[0] = a; @@ -362,7 +363,7 @@ continue; } for (aj = a; aj < an; *aj = r, aj = bin[c + 1]) - for (r = *aj; aj < (ak = --top[c = tr[r[depth]]]) ;) + for (r = *aj; aj < (ak = --top[c = tr[r[hdr_off]]]) ;) swap(*ak, r, t); for (ak = a, c = 0; c < 256; c++) {