replace linkedlist with arraylist in the expression parser

Sun, 20 Nov 2022 12:43:44 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 20 Nov 2022 12:43:44 +0100
changeset 437
545010bc5e71
parent 436
1260fad21be7
child 438
22eca559aded

replace linkedlist with arraylist in the expression parser

src/server/util/object.c file | annotate | diff | comparison | revisions
--- a/src/server/util/object.c	Sun Nov 20 12:19:09 2022 +0100
+++ b/src/server/util/object.c	Sun Nov 20 12:43:44 2022 +0100
@@ -28,6 +28,7 @@
 
 #include <cx/string.h>
 #include <cx/linked_list.h>
+#include <cx/array_list.h>
 #include <cx/compare.h>
 
 #include "../public/nsapi.h"
@@ -251,7 +252,7 @@
     if(stack->size == 0) {
         return NULL;
     }
-    NSAPIExpression *ret = cxListAt(stack, stack->size-1);
+    NSAPIExpression *ret = *((NSAPIExpression**)cxListAt(stack, stack->size-1));
     cxListRemove(stack, stack->size-1);
     return ret;
 }
@@ -290,7 +291,7 @@
         return 1; // error
     }
     
-    cxListAdd(parser->ex_stack, exp);
+    cxListAdd(parser->ex_stack, &exp);
     
     parser->expect_value = TRUE;
     parser->expect_arg = FALSE;
@@ -309,14 +310,14 @@
     exp->value.str = func->identifier;
     
     if(parser->ex_stack->size > 0) {
-        NSAPIExpression *top = cxListAt(parser->ex_stack, parser->ex_stack->size - 1);
+        NSAPIExpression *top = *((NSAPIExpression**)cxListAt(parser->ex_stack, parser->ex_stack->size - 1));
         if(top && top->operator == NSAPI_EXPRESSION_ARG) {
             exp->left = top;
             cxListRemove(parser->ex_stack, parser->ex_stack->size - 1);
         }
     }
     
-    if(cxListAdd(parser->ex_stack, exp)) {
+    if(cxListAdd(parser->ex_stack, &exp)) {
         return 1;
     }
     parser->expect_value = FALSE;
@@ -333,7 +334,7 @@
         return 1;
     }
     
-    cxListAdd(parser->ex_stack, exp);
+    cxListAdd(parser->ex_stack, &exp);
     if(parser->expect_arg) {
         ExprOpStackItem argList;
         argList.expect_value = TRUE;
@@ -482,12 +483,13 @@
         return NULL;
     }
     
-    return cxListAt(ex_stack, 0);
+    NSAPIExpression **ret = cxListAt(ex_stack, 0);
+    return *ret;
 }
 
 NSAPIExpression* expr_parse_logical_expr(pool_handle_t *pool, CxList *tokens, size_t *pos) {  
-    CxList *op_stack = cxLinkedListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(ExprOpStackItem));
-    CxList *ex_stack = cxPointerLinkedListCreate(pool_allocator(pool), cx_cmp_ptr);
+    CxList *op_stack = cxArrayListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(ExprOpStackItem), 32);
+    CxList *ex_stack = cxArrayListCreate(pool_allocator(pool), cx_cmp_ptr, sizeof(NSAPIExpression*), 32);
     
     ExprParser parser;
     parser.pool = pool;

mercurial