Преглед изворни кода

'nextvar' now traverses the symbol array, instead of the constant tree.

Roberto Ierusalimschy пре 30 година
родитељ
комит
15f40fddca
2 измењених фајлова са 14 додато и 32 уклоњено
  1. 12 30
      tree.c
  2. 2 2
      tree.h

+ 12 - 30
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); 
 }
 

+ 2 - 2
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