This commit is contained in:
hyung-hwan 2008-02-29 00:50:10 +00:00
parent fc5f81c189
commit ef7205c0ea
4 changed files with 67 additions and 13 deletions

View File

@ -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');

View File

@ -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)

View File

@ -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;

View File

@ -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)