diff --git a/ase/awk/Awk.cpp b/ase/awk/Awk.cpp index f563a152..1d7cb84c 100644 --- a/ase/awk/Awk.cpp +++ b/ase/awk/Awk.cpp @@ -1023,9 +1023,9 @@ void* Awk::Run::getCustom () const // Awk ////////////////////////////////////////////////////////////////// -Awk::Awk (): /*awk (ASE_NULL), functionMap (ASE_NULL), */ - sourceIn (Source::READ), sourceOut (Source::WRITE)/*, - errnum (ERR_NOERR), errlin (0), runCallback (false)*/ +Awk::Awk (): awk (ASE_NULL), functionMap (ASE_NULL), + sourceIn (Source::READ), sourceOut (Source::WRITE), + errnum (ERR_NOERR), errlin (0), runCallback (false) { this->errmsg[0] = ASE_T('\0'); diff --git a/ase/awk/val.c b/ase/awk/val.c index 012ea83d..72500227 100644 --- a/ase/awk/val.c +++ b/ase/awk/val.c @@ -319,20 +319,25 @@ ase_awk_val_t* ase_awk_makerexval ( ase_awk_val_rex_t* val; val = (ase_awk_val_rex_t*) ASE_AWK_MALLOC ( - run->awk, ASE_SIZEOF(ase_awk_val_rex_t)); + run->awk, ASE_SIZEOF(ase_awk_val_rex_t) + + (ASE_SIZEOF(*buf)*len+1) + ASE_AWK_REX_LEN(code)); if (val == ASE_NULL) return ASE_NULL; val->type = ASE_AWK_VAL_REX; val->ref = 0; val->len = len; + /* val->buf = ase_awk_strxdup (run->awk, buf, len); if (val->buf == ASE_NULL) { ASE_AWK_FREE (run->awk, val); ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); return ASE_NULL; - } + }*/ + val->buf = (ase_char_t*)(val + 1); + ase_strncpy (val->buf, buf, len); + /* val->code = ASE_AWK_MALLOC (run->awk, ASE_AWK_REX_LEN(code)); if (val->code == ASE_NULL) { @@ -341,8 +346,10 @@ ase_awk_val_t* ase_awk_makerexval ( ase_awk_setrunerrnum (run, ASE_AWK_ENOMEM); return ASE_NULL; } - + */ + val->code = val->buf + len + 1; ase_memcpy (val->code, code, ASE_AWK_REX_LEN(code)); + return (ase_awk_val_t*)val; } @@ -497,8 +504,10 @@ void ase_awk_freeval (ase_awk_run_t* run, ase_awk_val_t* val, ase_bool_t cache) } else if (val->type == ASE_AWK_VAL_REX) { + /* ASE_AWK_FREE (run->awk, ((ase_awk_val_rex_t*)val)->buf); ase_awk_freerex (run->awk, ((ase_awk_val_rex_t*)val)->code); + */ ASE_AWK_FREE (run->awk, val); } else if (val->type == ASE_AWK_VAL_MAP) diff --git a/ase/cmn/map.c b/ase/cmn/map.c index 5b46ccb4..f9ff7e22 100644 --- a/ase/cmn/map.c +++ b/ase/cmn/map.c @@ -17,6 +17,14 @@ static int rehash (ase_map_t* map); ASE_FREE ((map)->mmgr, pair); \ } while (0) +#define RECYCLE_PAIR(map,pair) \ + do { \ + if ((map)->freeval != ASE_NULL) \ + (map)->freeval ((map)->owner, ASE_PAIR_VAL(pair)); \ + (pair)->next = (map)->fp; \ + (map)->fp = (pair); \ + } while (0) + ase_map_t* ase_map_open ( void* owner, ase_size_t capa, unsigned int factor, void(*freeval)(void*,void*), void(*sameval)(void*,void*), @@ -48,6 +56,7 @@ ase_map_t* ase_map_open ( map->factor = factor; map->threshold = ((ase_size_t)map->factor) * map->capa / 100; + /*map->fp = ASE_NULL;*/ return map; } @@ -63,6 +72,15 @@ void ase_map_clear (ase_map_t* map) ase_size_t i; ase_pair_t* pair, * next; + /* + while (map->fp != ASE_NULL) + { + next = ASE_PAIR_LNK(map->fp); + ASE_FREE (map->mmgr, map->fp); + map->fp = next; + } + */ + for (i = 0; i < map->capa; i++) { pair = map->buck[i]; @@ -106,8 +124,7 @@ ase_pair_t* ase_map_get ( } ase_pair_t* ase_map_put ( - ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen, - void* val) + ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen, void* val) { int n; ase_pair_t* px; @@ -121,7 +138,7 @@ int ase_map_putx ( ase_map_t* map, const ase_char_t* keyptr, ase_size_t keylen, void* val, ase_pair_t** px) { - ase_pair_t* pair; + ase_pair_t* pair, * fp, * fp2; ase_size_t hc; hc = hashkey(keyptr,keylen) % map->capa; @@ -152,9 +169,32 @@ int ase_map_putx ( } } - pair = (ase_pair_t*) ASE_MALLOC (map->mmgr, - ASE_SIZEOF(ase_pair_t) + ((keylen+1)*ASE_SIZEOF(*keyptr))); - if (pair == ASE_NULL) return -1; /* error */ + + ASE_ASSERT (pair == ASE_NULL); + + /* + fp = map->fp; fp2 = ASE_NULL; + while (fp != ASE_NULL) + { + if (fp->key.len == keylen) + { + pair = fp; + if (fp2 == ASE_NULL) map->fp = fp->next; + else fp2->next = fp->next; + break; + } + + fp2 = fp; + fp = fp->next; + } + + if (pair == ASE_NULL) + { + */ + pair = (ase_pair_t*) ASE_MALLOC (map->mmgr, + ASE_SIZEOF(ase_pair_t) + ((keylen+1)*ASE_SIZEOF(*keyptr))); + if (pair == ASE_NULL) return -1; /* error */ + /*}*/ /* duplicate the key if it is new */ ASE_PAIR_KEYPTR(pair) = (ase_char_t*)(pair + 1); @@ -255,9 +295,11 @@ int ase_map_remove ( { if (prev == ASE_NULL) map->buck[hc] = ASE_PAIR_LNK(pair); - else prev->next = ASE_PAIR_LNK(pair); + else ASE_PAIR_LNK(prev) = ASE_PAIR_LNK(pair); + /*RECYCLE_PAIR (map, pair);*/ FREE_PAIR (map, pair); + map->size--; return 0; diff --git a/ase/cmn/map.h b/ase/cmn/map.h index 87bb9eb3..e5abbe5a 100644 --- a/ase/cmn/map.h +++ b/ase/cmn/map.h @@ -47,6 +47,9 @@ struct ase_map_t * while the map is alive as the contents are * not replicated */ ase_mmgr_t* mmgr; + + /* list of free pairs */ + /*ase_pair_t* fp;*/ }; #define ASE_PAIR_KEYPTR(p) ((p)->key.ptr)