summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOtto Moerbeek <otto@cvs.openbsd.org>2012-02-19 07:52:31 +0000
committerOtto Moerbeek <otto@cvs.openbsd.org>2012-02-19 07:52:31 +0000
commit0424fe73069409ab07e57212415b719a7ae7f8f1 (patch)
treea15576d70760c174f8ba02c84d81f846d7b2ac6c
parente677f17adc41d650ea11426ca2d736bcf82312e0 (diff)
Allow for more vars in hash table, improve hash function, increase
hash table size sooner. Based on suggestion from Michael Niedermayer. ok krw@ mpi@
-rw-r--r--bin/ksh/table.c10
-rw-r--r--bin/ksh/table.h4
2 files changed, 7 insertions, 7 deletions
diff --git a/bin/ksh/table.c b/bin/ksh/table.c
index cedc15f2807..74d16847341 100644
--- a/bin/ksh/table.c
+++ b/bin/ksh/table.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.c,v 1.14 2012/02/02 08:42:46 otto Exp $ */
+/* $OpenBSD: table.c,v 1.15 2012/02/19 07:52:30 otto Exp $ */
/*
* dynamic hashed associative table for commands and variables
@@ -18,8 +18,8 @@ hash(const char *n)
unsigned int h = 0;
while (*n != '\0')
- h = 2*h + *n++;
- return h * 32821; /* scatter bits */
+ h = 33*h + (unsigned char)(*n++);
+ return h;
}
void
@@ -44,7 +44,7 @@ texpand(struct table *tp, int nsize)
for (i = 0; i < nsize; i++)
ntblp[i] = NULL;
tp->size = nsize;
- tp->nfree = 8*nsize/10; /* table can get 80% full */
+ tp->nfree = 7*nsize/10; /* table can get 70% full */
tp->tbls = ntblp;
if (otblp == NULL)
return;
@@ -108,7 +108,7 @@ ktenter(struct table *tp, const char *n, unsigned int h)
}
if (tp->nfree <= 0) { /* too full */
- if (tp->size <= SHRT_MAX/2)
+ if (tp->size <= INT_MAX/2)
texpand(tp, 2*tp->size);
else
internal_errorf(1, "too many vars");
diff --git a/bin/ksh/table.h b/bin/ksh/table.h
index af080ad837a..3fe35eb0f52 100644
--- a/bin/ksh/table.h
+++ b/bin/ksh/table.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: table.h,v 1.7 2005/12/11 20:31:21 otto Exp $ */
+/* $OpenBSD: table.h,v 1.8 2012/02/19 07:52:30 otto Exp $ */
/* $From: table.h,v 1.3 1994/05/31 13:34:34 michael Exp $ */
@@ -8,7 +8,7 @@
struct table {
Area *areap; /* area to allocate entries */
- short size, nfree; /* hash size (always 2^^n), free entries */
+ int size, nfree; /* hash size (always 2^^n), free entries */
struct tbl **tbls; /* hashed table items */
};