much better solution: save tablep and hash value¹ in the struct tbl entry

① also saves time during texpand :D

XXX this doesn’t work well with the current indexed-array implementation
This commit is contained in:
tg
2009-08-28 20:30:59 +00:00
parent 7240c843ce
commit 4ccdfc8508
10 changed files with 108 additions and 110 deletions

27
exec.c
View File

@ -22,7 +22,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.63 2009/08/28 19:57:40 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/exec.c,v 1.64 2009/08/28 20:30:55 tg Exp $");
static int comexec(struct op *, struct tbl *volatile, const char **,
int volatile, volatile int *);
@ -567,7 +567,7 @@ comexec(struct op *t, struct tbl *volatile tp, const char **ap,
rv = 127;
break;
}
if (!(ftp = findfunc(cp, hash(cp), false, NULL)) ||
if (!(ftp = findfunc(cp, hash(cp), false)) ||
!(ftp->flag & ISSET)) {
warningf(true,
"%s: function not defined by %s",
@ -789,7 +789,7 @@ shcomexec(const char **wp)
{
struct tbl *tp;
tp = ktsearch(&builtins, *wp, hash(*wp), NULL);
tp = ktsearch(&builtins, *wp, hash(*wp));
if (tp == NULL)
internal_errorf("shcomexec: %s", *wp);
return (call_builtin(tp, wp));
@ -800,17 +800,17 @@ shcomexec(const char **wp)
* is created if none is found.
*/
struct tbl *
findfunc(const char *name, uint32_t h, bool create, struct table_entry *pte)
findfunc(const char *name, uint32_t h, bool create)
{
struct block *l;
struct tbl *tp = NULL;
for (l = e->loc; l; l = l->next) {
tp = ktsearch(&l->funs, name, h, pte);
tp = ktsearch(&l->funs, name, h);
if (tp)
break;
if (!l->next && create) {
tp = ktenter(&l->funs, name, h, pte);
tp = ktenter(&l->funs, name, h);
tp->flag = DEFINED;
tp->type = CFUNC;
tp->val.t = NULL;
@ -828,11 +828,10 @@ int
define(const char *name, struct op *t)
{
struct tbl *tp;
struct table_entry te;
bool was_set = false;
while (1) {
tp = findfunc(name, hash(name), true, &te);
tp = findfunc(name, hash(name), true);
if (tp->flag & ISSET)
was_set = true;
@ -853,7 +852,7 @@ define(const char *name, struct op *t)
}
if (t == NULL) { /* undefine */
ktremove(&te);
ktdelete(tp);
return (was_set ? 0 : 1);
}
@ -886,7 +885,7 @@ builtin(const char *name, int (*func) (const char **))
break;
}
tp = ktenter(&builtins, name, hash(name), NULL);
tp = ktenter(&builtins, name, hash(name));
tp->flag = DEFINED | flag;
tp->type = CSHELL;
tp->val.f = func;
@ -912,14 +911,14 @@ findcom(const char *name, int flags)
flags &= ~FC_FUNC;
goto Search;
}
tbi = (flags & FC_BI) ? ktsearch(&builtins, name, h, NULL) : NULL;
tbi = (flags & FC_BI) ? ktsearch(&builtins, name, h) : NULL;
/* POSIX says special builtins first, then functions, then
* POSIX regular builtins, then search path...
*/
if ((flags & FC_SPECBI) && tbi && (tbi->flag & SPEC_BI))
tp = tbi;
if (!tp && (flags & FC_FUNC)) {
tp = findfunc(name, h, false, NULL);
tp = findfunc(name, h, false);
if (tp && !(tp->flag & ISSET)) {
if ((fpath = str_val(global("FPATH"))) == null) {
tp->u.fpath = NULL;
@ -934,7 +933,7 @@ findcom(const char *name, int flags)
if (!tp && (flags & FC_UNREGBI) && tbi)
tp = tbi;
if (!tp && (flags & FC_PATH) && !(flags & FC_DEFPATH)) {
tp = ktsearch(&taliases, name, h, NULL);
tp = ktsearch(&taliases, name, h);
if (tp && (tp->flag & ISSET) && access(tp->val.s, X_OK) != 0) {
if (tp->flag & ALLOC) {
tp->flag &= ~ALLOC;
@ -949,7 +948,7 @@ findcom(const char *name, int flags)
(flags & FC_PATH)) {
if (!tp) {
if (insert && !(flags & FC_DEFPATH)) {
tp = ktenter(&taliases, name, h, NULL);
tp = ktenter(&taliases, name, h);
tp->type = CTALIAS;
} else {
tp = &temp;