[svn:parrot] r45343 - in branches/avl_string_cache: include/parrot src/string

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Mar 31 07:18:29 UTC 2010


Author: bacek
Date: Wed Mar 31 07:18:28 2010
New Revision: 45343
URL: https://trac.parrot.org/parrot/changeset/45343

Log:
Swap old const string hash with new AVL cache in interpeter

Modified:
   branches/avl_string_cache/include/parrot/interpreter.h
   branches/avl_string_cache/src/string/api.c

Modified: branches/avl_string_cache/include/parrot/interpreter.h
==============================================================================
--- branches/avl_string_cache/include/parrot/interpreter.h	Wed Mar 31 07:18:04 2010	(r45342)
+++ branches/avl_string_cache/include/parrot/interpreter.h	Wed Mar 31 07:18:28 2010	(r45343)
@@ -276,8 +276,8 @@
 
     struct _Caches * caches;                  /* see caches.h */
 
-    STRING     **const_cstring_table;         /* CONST_STRING(x) items */
-    Hash        *const_cstring_hash;          /* cache of const_string items */
+    STRING          **const_cstring_table;    /* CONST_STRING(x) items */
+    ConstStringTree  *const_string_cache;     /* cache of constant strings */
 
     struct QUEUE* task_queue;                 /* per interpreter queue */
     struct _handler_node_t *exit_handler_list;/* exit.c */

Modified: branches/avl_string_cache/src/string/api.c
==============================================================================
--- branches/avl_string_cache/src/string/api.c	Wed Mar 31 07:18:04 2010	(r45342)
+++ branches/avl_string_cache/src/string/api.c	Wed Mar 31 07:18:28 2010	(r45343)
@@ -305,14 +305,18 @@
     if (interp->parent_interpreter) {
         interp->const_cstring_table =
             interp->parent_interpreter->const_cstring_table;
-        interp->const_cstring_hash  =
-            interp->parent_interpreter->const_cstring_hash;
+        interp->const_string_cache  =
+            interp->parent_interpreter->const_string_cache;
         return;
     }
 
     /* Set up the cstring cache, then load the basic encodings and charsets */
-    const_cstring_hash          = parrot_new_cstring_hash(interp);
-    interp->const_cstring_hash  = const_cstring_hash;
+    interp->const_string_cache  =
+            (ConstStringTree*)Parrot_gc_allocate_fixed_size_storage(interp,
+                sizeof (ConstStringTree));
+    interp->const_string_cache->th_root = 0;
+    interp->const_string_cache->th_cmp  = Parrot_str_string_node_compare;
+
     Parrot_charsets_encodings_init(interp);
 
     /* initialize STRINGNULL, but not in the constant table */
@@ -326,13 +330,11 @@
     for (i = 0; i < n_parrot_cstrings; ++i) {
         DECL_CONST_CAST;
         STRING * const s =
-            Parrot_str_new_init(interp,
+            Parrot_str_new_constant_ex(interp,
                 parrot_cstrings[i].string,
                 parrot_cstrings[i].len,
                 PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
                 PObj_external_FLAG|PObj_constant_FLAG);
-        parrot_hash_put(interp, const_cstring_hash,
-            PARROT_const_cast(char *, parrot_cstrings[i].string), (void *)s);
         interp->const_cstring_table[i] = s;
     }
 }
@@ -357,7 +359,9 @@
         mem_internal_free(interp->const_cstring_table);
         interp->const_cstring_table = NULL;
         Parrot_charsets_encodings_deinit(interp);
-        parrot_hash_destroy(interp, interp->const_cstring_hash);
+        /* Don't deallocate const_string_cache. */
+        /* It's allocated from Fixed Size Allocator and will be cleaned */
+        /* automatically. */
     }
 }
 
@@ -786,7 +790,7 @@
         ARGIN(const ENCODING *encoding), ARGIN(const CHARSET *charset), UINTVAL flags)
 {
     ASSERT_ARGS(Parrot_str_new_constant_ex)
-    static ConstStringTree tree = TREE_INITIALIZER(Parrot_str_string_node_compare);
+    ConstStringTree *tree = interp->const_string_cache;
 
     /* Lookup old value */
     AVLStringNode node = {
@@ -794,10 +798,11 @@
         len,
         encoding,
         charset,
-        NULL
+        NULL,
+        { NULL, NULL, 0 }
     };
 
-    AVLStringNode *vv = TREE_FIND(&tree, avl_string_node_t, tree, &node);
+    AVLStringNode *vv = TREE_FIND(tree, avl_string_node_t, tree, &node);
     if (vv)
         return vv->value;
 
@@ -816,7 +821,7 @@
                        encoding, charset,
                        flags|PObj_constant_FLAG);
 
-    TREE_INSERT(&tree, avl_string_node_t, tree, vv);
+    TREE_INSERT(tree, avl_string_node_t, tree, vv);
 
     return vv->value;
 }


More information about the parrot-commits mailing list