commit 15f40fddca66301a53f8b0adf41958c7e9add945
parent 970995c3f258101ae90be4bcb762b6d38bb2b2fd
Author: Roberto Ierusalimschy <roberto@inf.puc-rio.br>
Date: Tue, 17 Oct 1995 09:53:34 -0200
'nextvar' now traverses the symbol array, instead of the constant tree.
Diffstat:
M | tree.c | | | 42 | ++++++++++++------------------------------ |
M | tree.h | | | 4 | ++-- |
2 files changed, 14 insertions(+), 32 deletions(-)
diff --git a/tree.c b/tree.c
@@ -3,7 +3,7 @@
** TecCGraf - PUC-Rio
*/
-char *rcs_tree="$Id: tree.c,v 1.12 1994/12/20 21:20:36 roberto Exp roberto $";
+char *rcs_tree="$Id: tree.c,v 1.13 1995/01/12 14:19:04 roberto Exp roberto $";
#include <string.h>
@@ -102,40 +102,22 @@ Long lua_strcollector (void)
return counter;
}
+
/*
-** Return next variable.
+** Traverse the constant tree looking for a specific symbol number
*/
-static TreeNode *tree_next (TreeNode *node, char *str)
+static TreeNode *nodebysymbol (TreeNode *root, Word symbol)
{
- if (node == NULL) return NULL;
- else if (str == NULL) return node;
- else
- {
- int c = lua_strcmp(str, node->ts.str);
- if (c == 0)
- return node->left != NULL ? node->left : node->right;
- else if (c < 0)
- {
- TreeNode *result = tree_next(node->left, str);
- return result != NULL ? result : node->right;
- }
- else
- return tree_next(node->right, str);
- }
+ TreeNode *t;
+ if (root == NULL) return NULL;
+ if (root->varindex == symbol) return root;
+ t = nodebysymbol(root->left, symbol);
+ if (t) return t;
+ return nodebysymbol(root->right, symbol);
}
-TreeNode *lua_varnext (char *n)
+TreeNode *luaI_nodebysymbol (Word symbol)
{
- TreeNode *result;
- char *name = n;
- while (1)
- { /* repeat until a valid (non nil) variable */
- result = tree_next(constant_root, name);
- if (result == NULL) return NULL;
- if (result->varindex != NOT_USED &&
- s_tag(result->varindex) != LUA_T_NIL)
- return result;
- name = result->ts.str;
- }
+ return nodebysymbol(constant_root, symbol);
}
diff --git a/tree.h b/tree.h
@@ -1,7 +1,7 @@
/*
** tree.h
** TecCGraf - PUC-Rio
-** $Id: tree.h,v 1.8 1994/12/20 21:20:36 roberto Exp roberto $
+** $Id: tree.h,v 1.9 1995/01/12 14:19:04 roberto Exp roberto $
*/
#ifndef tree_h
@@ -32,6 +32,6 @@ typedef struct TreeNode
TaggedString *lua_createstring (char *str);
TreeNode *lua_constcreate (char *str);
Long lua_strcollector (void);
-TreeNode *lua_varnext (char *n);
+TreeNode *luaI_nodebysymbol (Word symbol);
#endif