[svn:parrot] r38778 - trunk/src/pmc

chromatic at svn.parrot.org chromatic at svn.parrot.org
Thu May 14 21:33:50 UTC 2009


Author: chromatic
Date: Thu May 14 21:33:50 2009
New Revision: 38778
URL: https://trac.parrot.org/parrot/changeset/38778

Log:
[PMC] Avoided an unnecessary STRING copying and creation in NCI's
set_pointer_keyed_str VTABLE entry.  If the STRING is already constant, there's
no point in creating another constant string (even if we do cache constant
STRINGs).  This gets called mostly at initialization time, when initializing
MULTI variants from compile-time constants anyway.  This change speeds up
Parrot initialization by 2.59%.

Modified:
   trunk/src/pmc/nci.pmc

Modified: trunk/src/pmc/nci.pmc
==============================================================================
--- trunk/src/pmc/nci.pmc	Thu May 14 19:43:11 2009	(r38777)
+++ trunk/src/pmc/nci.pmc	Thu May 14 21:33:50 2009	(r38778)
@@ -178,13 +178,19 @@
     VTABLE void set_pointer_keyed_str(STRING *key, void *func) {
         Parrot_NCI_attributes * const nci_info = PARROT_NCI(SELF);
         int                             jitted = 0;
-        char                     * const key_c = Parrot_str_to_cstring(INTERP, key);
 
         /* Store the original function and signature. */
         SET_ATTR_orig_func(INTERP, SELF, func);
-        nci_info->signature  = string_make(interp, key_c, strlen(key_c),
+
+        /* ensure that the STRING signature is constant */
+        if (!PObj_constant_TEST(key)) {
+            char * const key_c = Parrot_str_to_cstring(INTERP, key);
+            key                = string_make(interp, key_c, strlen(key_c),
                                     NULL, PObj_constant_FLAG);
-        Parrot_str_free_cstring(key_c);
+            Parrot_str_free_cstring(key_c);
+        }
+
+        nci_info->signature  = key;
         pcc_params(INTERP, key, nci_info);
 
         /* Arity is length of that string minus one (the return type). */


More information about the parrot-commits mailing list