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

bacek at svn.parrot.org bacek at svn.parrot.org
Wed Mar 31 05:45:55 UTC 2010


Author: bacek
Date: Wed Mar 31 05:45:54 2010
New Revision: 45338
URL: https://trac.parrot.org/parrot/changeset/45338

Log:
Create function str_new_constant_ex (due lack of imagination for better name) to create new constant STRING with provided charset and encoding

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

Modified: branches/avl_string_cache/include/parrot/string.h
==============================================================================
--- branches/avl_string_cache/include/parrot/string.h	Wed Mar 31 05:35:40 2010	(r45337)
+++ branches/avl_string_cache/include/parrot/string.h	Wed Mar 31 05:45:54 2010	(r45338)
@@ -62,10 +62,10 @@
  * and simplify lookups */
 struct avl_string_node_t
 {
-    const char *      str;
-    size_t            length;
-    struct _encoding *encoding;
-    struct _charset  *charset;
+    const char              *str;
+    size_t                   length;
+    const struct _encoding  *encoding;
+    const struct _charset   *charset;
 
     STRING                  *value;
 

Modified: branches/avl_string_cache/include/parrot/string_funcs.h
==============================================================================
--- branches/avl_string_cache/include/parrot/string_funcs.h	Wed Mar 31 05:35:40 2010	(r45337)
+++ branches/avl_string_cache/include/parrot/string_funcs.h	Wed Mar 31 05:45:54 2010	(r45338)
@@ -286,6 +286,19 @@
         __attribute__nonnull__(2);
 
 PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+STRING * Parrot_str_new_constant_ex(PARROT_INTERP,
+    ARGIN_NULLOK(const char *buffer),
+    UINTVAL len,
+    ARGIN(const ENCODING *encoding),
+    ARGIN(const CHARSET *charset),
+    UINTVAL flags)
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(4)
+        __attribute__nonnull__(5);
+
+PARROT_EXPORT
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 STRING * Parrot_str_new_COW(PARROT_INTERP, ARGMOD(STRING *s))
@@ -642,6 +655,10 @@
 #define ASSERT_ARGS_Parrot_str_new_constant __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(buffer))
+#define ASSERT_ARGS_Parrot_str_new_constant_ex __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+       PARROT_ASSERT_ARG(interp) \
+    , PARROT_ASSERT_ARG(encoding) \
+    , PARROT_ASSERT_ARG(charset))
 #define ASSERT_ARGS_Parrot_str_new_COW __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(s))

Modified: branches/avl_string_cache/src/string/api.c
==============================================================================
--- branches/avl_string_cache/src/string/api.c	Wed Mar 31 05:35:40 2010	(r45337)
+++ branches/avl_string_cache/src/string/api.c	Wed Mar 31 05:45:54 2010	(r45338)
@@ -49,6 +49,7 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*s);
 
+static int string_node_compare(AVLStringNode *lhs, AVLStringNode *rhs);
 PARROT_INLINE
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
@@ -64,6 +65,7 @@
 #define ASSERT_ARGS_make_writable __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(interp) \
     , PARROT_ASSERT_ARG(s))
+#define ASSERT_ARGS_string_node_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_string_rep_compatible __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(a) \
     , PARROT_ASSERT_ARG(b) \
@@ -714,8 +716,9 @@
 }
 
 static int
-string_node_compare(AVLStringNode *lhs, AVLStringNode *rhs)
+string_node_compare(ARGIN(AVLStringNode *lhs), ARGIN(AVLStringNode *rhs))
 {
+    ASSERT_ARGS(string_node_compare)
     if (lhs->length < rhs->length)
         return -1;
     else if (lhs->length > rhs->length)
@@ -746,15 +749,34 @@
 Parrot_str_new_constant(PARROT_INTERP, ARGIN(const char *buffer))
 {
     ASSERT_ARGS(Parrot_str_new_constant)
-    DECL_CONST_CAST;
+    return Parrot_str_new_constant_ex(interp, buffer, strlen(buffer),
+            PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
+            PObj_external_FLAG);
+}
+
+/*
+=item C<Parrot_str_new_constant>
+
+=cut
+*/
 
+PARROT_EXPORT
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+STRING *
+Parrot_str_new_constant_ex(PARROT_INTERP, ARGIN_NULLOK(const char *buffer), UINTVAL len,
+        ARGIN(const ENCODING *encoding), ARGIN(const CHARSET *charset), UINTVAL flags)
+{
+    ASSERT_ARGS(Parrot_str_new_constant_ex)
     static ConstStringTree tree = TREE_INITIALIZER(string_node_compare);
 
     /* Lookup old value */
     AVLStringNode node = {
         buffer,
-        strlen(buffer),
-        NULL, NULL, NULL
+        len,
+        encoding,
+        charset,
+        NULL
     };
 
     AVLStringNode *vv = TREE_FIND(&tree, avl_string_node_t, tree, &node);
@@ -770,9 +792,9 @@
     vv->encoding = node.encoding;
     vv->charset  = node.charset;
 
-    vv->value = Parrot_str_new_init(interp, buffer, strlen(buffer),
-                       PARROT_DEFAULT_ENCODING, PARROT_DEFAULT_CHARSET,
-                       PObj_external_FLAG|PObj_constant_FLAG);
+    vv->value = Parrot_str_new_init(interp, buffer, len,
+                       encoding, charset,
+                       flags|PObj_constant_FLAG);
 
     TREE_INSERT(&tree, avl_string_node_t, tree, vv);
 


More information about the parrot-commits mailing list