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

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

From:
chromatic
Date:
December 7, 2008 12:53
Subject:
[svn:parrot] r33633 - trunk/src/pmc
Message ID:
20081207205320.BC4C0CB9AF@x12.develooper.com
Author: chromatic
Date: Sun Dec  7 12:53:19 2008
New Revision: 33633

Modified:
   trunk/src/pmc/class.pmc

Log:
[PMC] Revised Class PMC's isa_pmc() entry, which is a huge hotspot for Rakudo.
Most of the changes are to use string_free() on temporary strings, with some
additional refactoring to make control flow slightly clearer.

Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc	(original)
+++ trunk/src/pmc/class.pmc	Sun Dec  7 12:53:19 2008
@@ -204,8 +204,7 @@
                 "Failed to set namespace for class.");
 
         /* Set the name of the class to the name of the innermost namespace
-         * associated with the class.
-         */
+         * associated with the class.  */
         new_name = VTABLE_get_string(interp, new_namespace);
 
         if (STRING_IS_NULL(new_name) || STRING_IS_EMPTY(new_name))
@@ -1161,7 +1160,6 @@
 
     VTABLE INTVAL isa_pmc(PMC *lookup) {
         Parrot_Class_attributes * const _class    = PARROT_CLASS(SELF);
-        STRING       *classname, *self_name;
         PMC          *classobj;
         INTVAL        i, num_classes;
 
@@ -1179,21 +1177,26 @@
         /* Check if the class object is the same as self's class object */
         if (VTABLE_is_same(interp, SELF, classobj))
             return 1;
+        else {
+            STRING *classname = VTABLE_get_string(interp, classobj);
+            INTVAL  is_proxy  = SELF->vtable->base_type == enum_class_PMCProxy
+                               ? 1 : 0;
+
+            /* avoid the expensive string copy, if possible */
+            STRING *self_name = is_proxy
+                               ? VTABLE_get_string(interp, SELF)
+                               : make_class_name(interp, SELF);
+
+            /* Check if the passed name is the same as the stored short name. */
+            INTVAL name_match = string_equal(interp, classname, self_name) == 0;
+
+            string_free(interp, classname);
+            if (is_proxy)
+                string_free(interp, self_name);
 
-        classname = VTABLE_get_string(interp, classobj);
-
-        /* avoid the expensive string copy, if possible */
-        self_name = SELF->vtable->base_type != enum_class_PMCProxy
-                  ? make_class_name(interp, SELF)
-                  : VTABLE_get_string(interp, SELF);
-
-        /* Check if the passed name is the same as the stored short name. */
-        if (string_equal(interp, classname, self_name) == 0)
-            return 1;
-
-        /* Check if the passed name is the same as the fully qualified name. */
-        if (string_equal(interp, classname, VTABLE_get_string(interp, SELF)) == 0)
-            return 1;
+            if (name_match)
+                return 1;
+        }
 
         /* Iterate over all the parents and check if they respond true
          * for 'isa' on the original comparison. */



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