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

chromatic at svn.parrot.org chromatic at svn.parrot.org
Sat Sep 19 22:38:16 UTC 2009


Author: chromatic
Date: Sat Sep 19 22:38:15 2009
New Revision: 41372
URL: https://trac.parrot.org/parrot/changeset/41372

Log:
[PMC] Moved more logic from default PMC's isa_pmc() into Class's isa_pmc(),
where we can avoid COW STRINGs in almost every case.  There may be more
improvements here, but this change improves Rakudo's "Hello, world!" benchmark
by 6.327%.

Modified:
   trunk/src/pmc/class.pmc

Modified: trunk/src/pmc/class.pmc
==============================================================================
--- trunk/src/pmc/class.pmc	Sat Sep 19 22:38:10 2009	(r41371)
+++ trunk/src/pmc/class.pmc	Sat Sep 19 22:38:15 2009	(r41372)
@@ -1274,14 +1274,14 @@
 */
 
     VTABLE INTVAL isa_pmc(PMC *lookup) {
-        Parrot_Class_attributes * const _class    = PARROT_CLASS(SELF);
+        Parrot_Class_attributes * const _class = PARROT_CLASS(SELF);
         PMC          *classobj;
         INTVAL        i, num_classes;
 
         if (PMC_IS_NULL(lookup))
             return 0;
 
-        if (SUPER(lookup))
+        if (PObj_is_class_TEST(lookup) && lookup == SELF)
             return 1;
 
         classobj = Parrot_oo_get_class(interp, lookup);
@@ -1293,6 +1293,22 @@
         if (VTABLE_is_same(interp, SELF, classobj))
             return 1;
 
+        /* this is effectively what the default PMC's isa_pmc does
+         * ... but this can cheat and avoid COW STRINGs for the classobj
+         * only in these two, very specific and common cases */
+        if (classobj->vtable->base_type == enum_class_Class
+        ||  classobj->vtable->base_type == enum_class_PMCProxy) {
+            STRING *classname = make_class_name(interp, classobj);
+
+            if (Parrot_str_equal(interp, SELF->vtable->whoami, classname))
+                return 1;
+
+            if (SELF->vtable->isa_hash
+            &&  parrot_hash_exists(interp, SELF->vtable->isa_hash,
+                                    (void *)classname))
+                return 1;
+        }
+
         /* Iterate over all the parents and check if they respond true
          * for 'isa' on the original comparison. */
         num_classes = VTABLE_elements(interp, _class->parents);


More information about the parrot-commits mailing list