develooper Front page | perl.cvs.parrot | Postings from December 2008

[svn:parrot] r33631 - in trunk: include/parrot src

From:
chromatic
Date:
December 7, 2008 12:40
Subject:
[svn:parrot] r33631 - in trunk: include/parrot src
Message ID:
20081207204030.D14D4CB9AF@x12.develooper.com
Author: chromatic
Date: Sun Dec  7 12:40:26 2008
New Revision: 33631

Modified:
   trunk/include/parrot/string_funcs.h
   trunk/src/string.c

Log:
[src] Added string_free(), along the lines of temporary_pmc_free() and with
similar caveats.  This function lets you recycle a STRING header you *know* is
unused.  It also respects COW semantics.  In a single hotspot, this function
gives us a 9.16% improvement in the Rakudo-building benchmark.

Modified: trunk/include/parrot/string_funcs.h
==============================================================================
--- trunk/include/parrot/string_funcs.h	(original)
+++ trunk/include/parrot/string_funcs.h	Sun Dec  7 12:40:26 2008
@@ -523,6 +523,10 @@
         __attribute__nonnull__(2)
         FUNC_MODIFIES(*tc);
 
+void string_free(PARROT_INTERP, ARGIN(STRING *s))
+        __attribute__nonnull__(1)
+        __attribute__nonnull__(2);
+
 PARROT_WARN_UNUSED_RESULT
 PARROT_CANNOT_RETURN_NULL
 STRING* uint_to_str(PARROT_INTERP,

Modified: trunk/src/string.c
==============================================================================
--- trunk/src/string.c	(original)
+++ trunk/src/string.c	Sun Dec  7 12:40:26 2008
@@ -222,7 +222,6 @@
         return dest;
     if (dest) { /* && dest != src */
         /* they are different, dest is not an external string */
-    /* TODO create string_free API for reusing string headers */
 #ifdef GC_IS_MALLOC
         if (!PObj_is_cowed_TESTALL(dest) && PObj_bufstart(dest)) {
             mem_sys_free(PObj_bufallocstart(dest));
@@ -235,6 +234,29 @@
     return dest;
 }
 
+
+/*
+
+=item C<void string_free>
+
+Frees the given STRING's header, accounting for reference counts for the
+STRING's buffer &c.  Use this only if you I<know> that nothing else has stored
+the STRING elsewhere.
+
+=cut
+
+*/
+
+PARROT_INLINE
+void
+string_free(PARROT_INTERP, ARGIN(STRING *s))
+{
+    if (!PObj_constant_TEST(s)) {
+        Small_Object_Pool *pool = interp->arena_base->string_header_pool;
+        pool->add_free_object(interp, pool, s);
+    }
+}
+
 /*
 
 =back



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About