… but since I liked the bonus of having the hval stored so much, merge
it with the array index; var.c says that │ 1244 /* The table entry is always [0] */ so that we can have a special flag and a union which stores hval for the table index, the array index otherwise (coïncidentally *hint hint* they have the same size)
This commit is contained in:
parent
bb7a720a00
commit
9b8d4023fa
4
expr.c
4
expr.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.32 2009/08/28 20:38:41 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/expr.c,v 1.33 2009/08/28 21:01:25 tg Exp $");
|
||||
|
||||
/* The order of these enums is constrained by the order of opinfo[] */
|
||||
enum token {
|
||||
@ -610,8 +610,8 @@ tempvar(void)
|
||||
vp->areap = ATEMP;
|
||||
#ifdef notyet_ktremove
|
||||
vp->tablep = NULL;
|
||||
vp->hval = 0;
|
||||
#endif
|
||||
vp->ua.hval = 0;
|
||||
vp->val.i = 0;
|
||||
vp->name[0] = '\0';
|
||||
return (vp);
|
||||
|
6
funcs.c
6
funcs.c
@ -25,7 +25,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.123 2009/08/28 20:30:56 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/funcs.c,v 1.124 2009/08/28 21:01:25 tg Exp $");
|
||||
|
||||
#if HAVE_KILLPG
|
||||
/*
|
||||
@ -1010,7 +1010,9 @@ c_typeset(const char **wp)
|
||||
if ((vp->flag&ARRAY) && any_set)
|
||||
shprintf("%s[%lu]",
|
||||
vp->name,
|
||||
(unsigned long)vp->index);
|
||||
vp->flag & AINDEX ?
|
||||
(unsigned long)vp->ua.index :
|
||||
0);
|
||||
else
|
||||
shf_puts(vp->name, shl_stdout);
|
||||
if (thing == '-' && (vp->flag&ISSET)) {
|
||||
|
19
main.c
19
main.c
@ -33,7 +33,7 @@
|
||||
#include <locale.h>
|
||||
#endif
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.141 2009/08/28 20:38:42 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.142 2009/08/28 21:01:26 tg Exp $");
|
||||
|
||||
extern char **environ;
|
||||
|
||||
@ -1278,13 +1278,8 @@ texpand(struct table *tp, size_t nsize)
|
||||
for (i = 0; i < osize; i++)
|
||||
if ((tblp = otblp[i]) != NULL) {
|
||||
if ((tblp->flag & DEFINED)) {
|
||||
#ifdef notyet_ktremove
|
||||
for (p = &ntblp[tblp->hval &
|
||||
for (p = &ntblp[tblp->ua.hval &
|
||||
(tp->size - 1)]; *p != NULL; p--)
|
||||
#else
|
||||
for (p = &ntblp[hash(tblp->name) &
|
||||
(tp->size - 1)]; *p != NULL; p--)
|
||||
#endif
|
||||
if (p == ntblp) /* wrap */
|
||||
p += tp->size;
|
||||
*p = tblp;
|
||||
@ -1314,12 +1309,8 @@ ktscan(struct table *tp, const char *n, uint32_t h, struct tbl ***ppp)
|
||||
|
||||
/* search for name in hashed table */
|
||||
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
||||
#ifdef notyet_ktremove
|
||||
if (p->hval == h && !strcmp(p->name, n) && (p->flag & DEFINED))
|
||||
#else
|
||||
if (*p->name == *n && !strcmp(p->name, n) &&
|
||||
if (p->ua.hval == h && !strcmp(p->name, n) &&
|
||||
(p->flag & DEFINED))
|
||||
#endif
|
||||
goto found;
|
||||
if (pp == tp->tbls)
|
||||
/* wrap */
|
||||
@ -1368,8 +1359,8 @@ ktenter(struct table *tp, const char *n, uint32_t h)
|
||||
p->areap = tp->areap;
|
||||
#ifdef notyet_ktremove
|
||||
p->tablep = tp;
|
||||
p->hval = h;
|
||||
#endif
|
||||
p->ua.hval = h;
|
||||
p->u2.field = 0;
|
||||
p->u.array = NULL;
|
||||
memcpy(p->name, n, len);
|
||||
@ -1387,7 +1378,7 @@ ktremove(struct tbl *p)
|
||||
struct tbl **pp;
|
||||
|
||||
if (p->tablep && p->tablep->size && ktscan(p->tablep, p->name,
|
||||
p->hval, &pp) == p) {
|
||||
p->ua.hval, &pp) == p) {
|
||||
/* ktremove p */
|
||||
*pp = NULL;
|
||||
p->tablep->nfree++;
|
||||
|
11
sh.h
11
sh.h
@ -134,7 +134,7 @@
|
||||
#endif
|
||||
|
||||
#ifdef EXTERN
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.329 2009/08/28 20:38:42 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.330 2009/08/28 21:01:26 tg Exp $");
|
||||
#endif
|
||||
#define MKSH_VERSION "R39 2009/08/08"
|
||||
|
||||
@ -874,10 +874,10 @@ struct tbl { /* table item */
|
||||
int type; /* command type (see below), base (if INTEGER),
|
||||
* or offset from val.s of value (if EXPORT) */
|
||||
Tflag flag; /* flags */
|
||||
#ifdef notyet_ktremove
|
||||
uint32_t hval; /* hash(name) */
|
||||
#endif
|
||||
uint32_t index; /* index for an array */
|
||||
union {
|
||||
uint32_t hval; /* hash(name) */
|
||||
uint32_t index; /* index for an array */
|
||||
} ua;
|
||||
char name[4]; /* name -- variable length */
|
||||
};
|
||||
|
||||
@ -905,6 +905,7 @@ struct tbl { /* table item */
|
||||
#define LOCAL_COPY BIT(22) /* with LOCAL - copy attrs from existing var */
|
||||
#define EXPRINEVAL BIT(23) /* contents currently being evaluated */
|
||||
#define EXPRLVALUE BIT(24) /* useable as lvalue (temp flag) */
|
||||
#define AINDEX BIT(25) /* array index >0 = ua.index filled in */
|
||||
/* flag bits used for taliases/builtins/aliases/keywords/functions */
|
||||
#define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */
|
||||
#define FINUSE BIT(9) /* function being executed */
|
||||
|
17
var.c
17
var.c
@ -22,7 +22,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.81 2009/08/28 20:38:43 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.82 2009/08/28 21:01:27 tg Exp $");
|
||||
|
||||
/*
|
||||
* Variables
|
||||
@ -1241,35 +1241,34 @@ arraysearch(struct tbl *vp, uint32_t val)
|
||||
size_t len;
|
||||
|
||||
vp->flag |= ARRAY|DEFINED;
|
||||
vp->index = 0;
|
||||
/* The table entry is always [0] */
|
||||
if (val == 0)
|
||||
return (vp);
|
||||
prev = vp;
|
||||
curr = vp->u.array;
|
||||
while (curr && curr->index < val) {
|
||||
while (curr && curr->ua.index < val) {
|
||||
prev = curr;
|
||||
curr = curr->u.array;
|
||||
}
|
||||
if (curr && curr->index == val) {
|
||||
if (curr && curr->ua.index == val) {
|
||||
if (curr->flag&ISSET)
|
||||
return (curr);
|
||||
new = curr;
|
||||
} else
|
||||
new = NULL;
|
||||
len = strlen(vp->name) + 1;
|
||||
if (!new)
|
||||
if (!new) {
|
||||
new = alloc(offsetof(struct tbl, name[0]) + len, vp->areap);
|
||||
memcpy(new->name, vp->name, len);
|
||||
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
||||
memcpy(new->name, vp->name, len);
|
||||
}
|
||||
new->flag = (vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL)) | AINDEX;
|
||||
new->type = vp->type;
|
||||
new->areap = vp->areap;
|
||||
new->u2.field = vp->u2.field;
|
||||
new->index = val;
|
||||
new->ua.index = val;
|
||||
#ifdef notyet_ktremove
|
||||
/* XXX array indices must not be ktdelete'd, for now */
|
||||
new->tablep = NULL;
|
||||
new->hval = vp->hval;
|
||||
#endif
|
||||
|
||||
if (curr != new) { /* not reusing old array entry */
|
||||
|
Loading…
x
Reference in New Issue
Block a user