From 088cc3f3802b98e613f1348b15679ecd187a435b Mon Sep 17 00:00:00 2001 From: Waldemar Celes Date: Fri, 5 Aug 1994 16:25:09 -0300 Subject: evitar, durante consultas, criacao de nos nao encontrados. --- hash.c | 17 ++++++++++++++++- hash.h | 3 ++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/hash.c b/hash.c index 0b823092..143c6f55 100644 --- a/hash.c +++ b/hash.c @@ -4,7 +4,7 @@ ** Luiz Henrique de Figueiredo - 17 Aug 90 */ -char *rcs_hash="$Id: hash.c,v 2.1 1994/04/20 22:07:57 celes Exp celes $"; +char *rcs_hash="$Id: hash.c,v 2.2 1994/07/19 21:27:18 celes Exp celes $"; #include #include @@ -212,6 +212,21 @@ Hash *lua_createarray (int nhash) } +/* +** If the hash node is present, return its pointer, otherwise return a +** static nil object +*/ +Object *lua_hashget (Hash *t, Object *ref) +{ + static Object nil_obj = {T_NIL, {NULL}}; + Node *n; + int h = head (t, ref); + if (h < 0) return NULL; + n = present(t, ref, h); + if (n == NULL) return &nil_obj; + else return &n->val; +} + /* ** If the hash node is present, return its pointer, otherwise create a new ** node for the given reference and also return its pointer. diff --git a/hash.h b/hash.h index cea34df1..f296ec8d 100644 --- a/hash.h +++ b/hash.h @@ -2,7 +2,7 @@ ** hash.h ** hash manager for lua ** Luiz Henrique de Figueiredo - 17 Aug 90 -** $Id: hash.h,v 1.1 1993/12/17 18:41:19 celes Exp celes $ +** $Id: hash.h,v 2.1 1994/04/20 22:07:57 celes Exp celes $ */ #ifndef hash_h @@ -26,6 +26,7 @@ typedef struct Hash Hash *lua_createarray (int nhash); void lua_hashmark (Hash *h); void lua_hashcollector (void); +Object *lua_hashget (Hash *t, Object *ref); Object *lua_hashdefine (Hash *t, Object *ref); void lua_next (void); -- cgit v1.2.3-55-g6feb