… 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"
|
#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[] */
|
/* The order of these enums is constrained by the order of opinfo[] */
|
||||||
enum token {
|
enum token {
|
||||||
@ -610,8 +610,8 @@ tempvar(void)
|
|||||||
vp->areap = ATEMP;
|
vp->areap = ATEMP;
|
||||||
#ifdef notyet_ktremove
|
#ifdef notyet_ktremove
|
||||||
vp->tablep = NULL;
|
vp->tablep = NULL;
|
||||||
vp->hval = 0;
|
|
||||||
#endif
|
#endif
|
||||||
|
vp->ua.hval = 0;
|
||||||
vp->val.i = 0;
|
vp->val.i = 0;
|
||||||
vp->name[0] = '\0';
|
vp->name[0] = '\0';
|
||||||
return (vp);
|
return (vp);
|
||||||
|
6
funcs.c
6
funcs.c
@ -25,7 +25,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
#if HAVE_KILLPG
|
||||||
/*
|
/*
|
||||||
@ -1010,7 +1010,9 @@ c_typeset(const char **wp)
|
|||||||
if ((vp->flag&ARRAY) && any_set)
|
if ((vp->flag&ARRAY) && any_set)
|
||||||
shprintf("%s[%lu]",
|
shprintf("%s[%lu]",
|
||||||
vp->name,
|
vp->name,
|
||||||
(unsigned long)vp->index);
|
vp->flag & AINDEX ?
|
||||||
|
(unsigned long)vp->ua.index :
|
||||||
|
0);
|
||||||
else
|
else
|
||||||
shf_puts(vp->name, shl_stdout);
|
shf_puts(vp->name, shl_stdout);
|
||||||
if (thing == '-' && (vp->flag&ISSET)) {
|
if (thing == '-' && (vp->flag&ISSET)) {
|
||||||
|
19
main.c
19
main.c
@ -33,7 +33,7 @@
|
|||||||
#include <locale.h>
|
#include <locale.h>
|
||||||
#endif
|
#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;
|
extern char **environ;
|
||||||
|
|
||||||
@ -1278,13 +1278,8 @@ texpand(struct table *tp, size_t nsize)
|
|||||||
for (i = 0; i < osize; i++)
|
for (i = 0; i < osize; i++)
|
||||||
if ((tblp = otblp[i]) != NULL) {
|
if ((tblp = otblp[i]) != NULL) {
|
||||||
if ((tblp->flag & DEFINED)) {
|
if ((tblp->flag & DEFINED)) {
|
||||||
#ifdef notyet_ktremove
|
for (p = &ntblp[tblp->ua.hval &
|
||||||
for (p = &ntblp[tblp->hval &
|
|
||||||
(tp->size - 1)]; *p != NULL; p--)
|
(tp->size - 1)]; *p != NULL; p--)
|
||||||
#else
|
|
||||||
for (p = &ntblp[hash(tblp->name) &
|
|
||||||
(tp->size - 1)]; *p != NULL; p--)
|
|
||||||
#endif
|
|
||||||
if (p == ntblp) /* wrap */
|
if (p == ntblp) /* wrap */
|
||||||
p += tp->size;
|
p += tp->size;
|
||||||
*p = tblp;
|
*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 */
|
/* search for name in hashed table */
|
||||||
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
for (pp = &tp->tbls[h & (tp->size - 1)]; (p = *pp) != NULL; pp--) {
|
||||||
#ifdef notyet_ktremove
|
if (p->ua.hval == h && !strcmp(p->name, n) &&
|
||||||
if (p->hval == h && !strcmp(p->name, n) && (p->flag & DEFINED))
|
|
||||||
#else
|
|
||||||
if (*p->name == *n && !strcmp(p->name, n) &&
|
|
||||||
(p->flag & DEFINED))
|
(p->flag & DEFINED))
|
||||||
#endif
|
|
||||||
goto found;
|
goto found;
|
||||||
if (pp == tp->tbls)
|
if (pp == tp->tbls)
|
||||||
/* wrap */
|
/* wrap */
|
||||||
@ -1368,8 +1359,8 @@ ktenter(struct table *tp, const char *n, uint32_t h)
|
|||||||
p->areap = tp->areap;
|
p->areap = tp->areap;
|
||||||
#ifdef notyet_ktremove
|
#ifdef notyet_ktremove
|
||||||
p->tablep = tp;
|
p->tablep = tp;
|
||||||
p->hval = h;
|
|
||||||
#endif
|
#endif
|
||||||
|
p->ua.hval = h;
|
||||||
p->u2.field = 0;
|
p->u2.field = 0;
|
||||||
p->u.array = NULL;
|
p->u.array = NULL;
|
||||||
memcpy(p->name, n, len);
|
memcpy(p->name, n, len);
|
||||||
@ -1387,7 +1378,7 @@ ktremove(struct tbl *p)
|
|||||||
struct tbl **pp;
|
struct tbl **pp;
|
||||||
|
|
||||||
if (p->tablep && p->tablep->size && ktscan(p->tablep, p->name,
|
if (p->tablep && p->tablep->size && ktscan(p->tablep, p->name,
|
||||||
p->hval, &pp) == p) {
|
p->ua.hval, &pp) == p) {
|
||||||
/* ktremove p */
|
/* ktremove p */
|
||||||
*pp = NULL;
|
*pp = NULL;
|
||||||
p->tablep->nfree++;
|
p->tablep->nfree++;
|
||||||
|
11
sh.h
11
sh.h
@ -134,7 +134,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef EXTERN
|
#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
|
#endif
|
||||||
#define MKSH_VERSION "R39 2009/08/08"
|
#define MKSH_VERSION "R39 2009/08/08"
|
||||||
|
|
||||||
@ -874,10 +874,10 @@ struct tbl { /* table item */
|
|||||||
int type; /* command type (see below), base (if INTEGER),
|
int type; /* command type (see below), base (if INTEGER),
|
||||||
* or offset from val.s of value (if EXPORT) */
|
* or offset from val.s of value (if EXPORT) */
|
||||||
Tflag flag; /* flags */
|
Tflag flag; /* flags */
|
||||||
#ifdef notyet_ktremove
|
union {
|
||||||
uint32_t hval; /* hash(name) */
|
uint32_t hval; /* hash(name) */
|
||||||
#endif
|
uint32_t index; /* index for an array */
|
||||||
uint32_t index; /* index for an array */
|
} ua;
|
||||||
char name[4]; /* name -- variable length */
|
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 LOCAL_COPY BIT(22) /* with LOCAL - copy attrs from existing var */
|
||||||
#define EXPRINEVAL BIT(23) /* contents currently being evaluated */
|
#define EXPRINEVAL BIT(23) /* contents currently being evaluated */
|
||||||
#define EXPRLVALUE BIT(24) /* useable as lvalue (temp flag) */
|
#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 */
|
/* flag bits used for taliases/builtins/aliases/keywords/functions */
|
||||||
#define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */
|
#define KEEPASN BIT(8) /* keep command assignments (eg, var=x cmd) */
|
||||||
#define FINUSE BIT(9) /* function being executed */
|
#define FINUSE BIT(9) /* function being executed */
|
||||||
|
17
var.c
17
var.c
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#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
|
* Variables
|
||||||
@ -1241,35 +1241,34 @@ arraysearch(struct tbl *vp, uint32_t val)
|
|||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
vp->flag |= ARRAY|DEFINED;
|
vp->flag |= ARRAY|DEFINED;
|
||||||
vp->index = 0;
|
|
||||||
/* The table entry is always [0] */
|
/* The table entry is always [0] */
|
||||||
if (val == 0)
|
if (val == 0)
|
||||||
return (vp);
|
return (vp);
|
||||||
prev = vp;
|
prev = vp;
|
||||||
curr = vp->u.array;
|
curr = vp->u.array;
|
||||||
while (curr && curr->index < val) {
|
while (curr && curr->ua.index < val) {
|
||||||
prev = curr;
|
prev = curr;
|
||||||
curr = curr->u.array;
|
curr = curr->u.array;
|
||||||
}
|
}
|
||||||
if (curr && curr->index == val) {
|
if (curr && curr->ua.index == val) {
|
||||||
if (curr->flag&ISSET)
|
if (curr->flag&ISSET)
|
||||||
return (curr);
|
return (curr);
|
||||||
new = curr;
|
new = curr;
|
||||||
} else
|
} else
|
||||||
new = NULL;
|
new = NULL;
|
||||||
len = strlen(vp->name) + 1;
|
len = strlen(vp->name) + 1;
|
||||||
if (!new)
|
if (!new) {
|
||||||
new = alloc(offsetof(struct tbl, name[0]) + len, vp->areap);
|
new = alloc(offsetof(struct tbl, name[0]) + len, vp->areap);
|
||||||
memcpy(new->name, vp->name, len);
|
memcpy(new->name, vp->name, len);
|
||||||
new->flag = vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL);
|
}
|
||||||
|
new->flag = (vp->flag & ~(ALLOC|DEFINED|ISSET|SPECIAL)) | AINDEX;
|
||||||
new->type = vp->type;
|
new->type = vp->type;
|
||||||
new->areap = vp->areap;
|
new->areap = vp->areap;
|
||||||
new->u2.field = vp->u2.field;
|
new->u2.field = vp->u2.field;
|
||||||
new->index = val;
|
new->ua.index = val;
|
||||||
#ifdef notyet_ktremove
|
#ifdef notyet_ktremove
|
||||||
/* XXX array indices must not be ktdelete'd, for now */
|
/* XXX array indices must not be ktdelete'd, for now */
|
||||||
new->tablep = NULL;
|
new->tablep = NULL;
|
||||||
new->hval = vp->hval;
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (curr != new) { /* not reusing old array entry */
|
if (curr != new) { /* not reusing old array entry */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user