From 5204e7cc4f46cec7cfc8c70522a4daceade43ab5 Mon Sep 17 00:00:00 2001 From: tg Date: Sun, 22 Apr 2012 21:50:35 +0000 Subject: [PATCH] after discussion with ciruZ, switch mksh from NZAT to NZAAT fully to get rid of the bias introduced by making the hash never zero MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit … he also pointed out a memory (heap) usage optimisation… which may impact code size a bit though as I’d need to pass an additional argument on hashtable function calls… or, forgo the benefit of not having to pointer-align the key in the structure, which can be as much as 3/7 octets per item, heap storage… OTOH the saved space is 4/8 octets per not-allocated item, possibly some code (use of an multiply-add opcode), but the function call overhead/cost would possibly be quite a bit… I guess I’ll have to measure… --- check.t | 6 +++--- eval.c | 4 ++-- mksh.1 | 6 +++--- sh.h | 15 +++------------ var.c | 4 ++-- 5 files changed, 13 insertions(+), 22 deletions(-) diff --git a/check.t b/check.t index d257067..fd28e6b 100644 --- a/check.t +++ b/check.t @@ -1,4 +1,4 @@ -# $MirOS: src/bin/mksh/check.t,v 1.532 2012/04/14 16:07:44 tg Exp $ +# $MirOS: src/bin/mksh/check.t,v 1.533 2012/04/22 21:50:29 tg Exp $ # $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $ # $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $ @@ -29,7 +29,7 @@ # http://www.freebsd.org/cgi/cvsweb.cgi/src/tools/regression/bin/test/regress.sh?rev=HEAD expected-stdout: - @(#)MIRBSD KSH R40 2012/04/14 + @(#)MIRBSD KSH R40 2012/04/22 description: Check version of shell. stdin: @@ -7089,7 +7089,7 @@ stdin: print ${foo@#123} ${bar@#456} ${baz@#789} . print ${foo@#bla} ${bar@#bar} ${baz@#OPTIND} . expected-stdout: - D50219A0 20E5DB5B 00000001 . + D50219A0 20E5DB5B 00000000 . 554A1C76 004A212E CB209562 . 6B21CF91 20E5DB5B 124EA49D . --- diff --git a/eval.c b/eval.c index 3c691cc..c71c66f 100644 --- a/eval.c +++ b/eval.c @@ -23,7 +23,7 @@ #include "sh.h" -__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.116 2012/04/06 14:07:52 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.117 2012/04/22 21:50:31 tg Exp $"); /* * string expansion @@ -392,7 +392,7 @@ expand(const char *cp, /* input word */ h = seed; NZATUpdateString(h, str_val(st->var)); - NZATFinish(h); + NZAATFinish(h); x.str = shf_smprintf("%08X", (unsigned int)h); break; diff --git a/mksh.1 b/mksh.1 index 4616bdc..1d4576d 100644 --- a/mksh.1 +++ b/mksh.1 @@ -1,4 +1,4 @@ -.\" $MirOS: src/bin/mksh/mksh.1,v 1.284 2012/04/14 12:51:34 tg Exp $ +.\" $MirOS: src/bin/mksh/mksh.1,v 1.285 2012/04/22 21:50:32 tg Exp $ .\" $OpenBSD: ksh.1,v 1.141 2011/09/03 22:59:08 jmc Exp $ .\"- .\" Copyright © 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, @@ -74,7 +74,7 @@ .\" with -mandoc, it might implement .Mx itself, but we want to .\" use our own definition. And .Dd must come *first*, always. .\" -.Dd $Mdocdate: April 14 2012 $ +.Dd $Mdocdate: April 22 2012 $ .\" .\" Check which macro package we use, and do other -mdoc setup. .\" @@ -1626,7 +1626,7 @@ The internal hash of the expansion of .Ar name , with an optional (defaulting to zero) .Ar seed . -At the moment, this is NZAT (a never-zero 32-bit hash based on +At the moment, this is NZAAT (a 32-bit hash based on Bob Jenkins' one-at-a-time hash), but this is not set. This is the hash the shell uses internally for its associative arrays. .El diff --git a/sh.h b/sh.h index a22bef1..996f1aa 100644 --- a/sh.h +++ b/sh.h @@ -152,9 +152,9 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.549 2012/04/14 16:07:48 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.550 2012/04/22 21:50:33 tg Exp $"); #endif -#define MKSH_VERSION "R40 2012/04/14" +#define MKSH_VERSION "R40 2012/04/22" /* arithmetic types: C implementation */ #if !HAVE_CAN_INTTYPES @@ -1491,7 +1491,7 @@ EXTERN struct timeval j_usrtime, j_systime; } while (/* CONSTCOND */ 0) -/* NZAT/NZAAT hashes based on Bob Jenkins' one-at-a-time hash */ +/* NZAAT hash based on Bob Jenkins' one-at-a-time hash */ /* From: src/kern/include/nzat.h,v 1.2 2011/07/18 00:35:40 tg Exp $ */ @@ -1524,15 +1524,6 @@ EXTERN struct timeval j_usrtime, j_systime; NZATUpdateByte((h), NZATUpdateString_c); \ } while (/* CONSTCOND */ 0) -/* not zero after termination */ -#define NZATFinish(h) do { \ - if ((h) == 0) \ - ++(h); \ - else \ - NZAATFinish(h); \ -} while (/* CONSTCOND */ 0) - -/* NULs zählen an allen Teilen */ #define NZAATFinish(h) do { \ (h) += (h) << 10; \ (h) ^= (h) >> 6; \ diff --git a/var.c b/var.c index fcaf6e5..26462f0 100644 --- a/var.c +++ b/var.c @@ -27,7 +27,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.146 2012/04/14 14:35:13 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.147 2012/04/22 21:50:35 tg Exp $"); /*- * Variables @@ -1471,7 +1471,7 @@ hash(const void *s) NZATInit(h); NZATUpdateString(h, s); - NZATFinish(h); + NZAATFinish(h); return (h); }