[svn:parrot] r38823 - in trunk: lib/Parrot/Pmc2c src/pmc
chromatic at svn.parrot.org
chromatic at svn.parrot.org
Sat May 16 10:45:29 UTC 2009
Author: chromatic
Date: Sat May 16 10:45:28 2009
New Revision: 38823
URL: https://trac.parrot.org/parrot/changeset/38823
Log:
[PMC] Modified PMC generator to skip the isa_hash in the case where the PMC has
no superclass besides itself. This allows the appropriate isa and isa_pmc
VTABLE entries to perform a simple exact match instead of the comparatively
expensive hash lookup for type equivalence.
Modified:
trunk/lib/Parrot/Pmc2c/PMCEmitter.pm
trunk/src/pmc/default.pmc
trunk/src/pmc/pmcproxy.pmc
Modified: trunk/lib/Parrot/Pmc2c/PMCEmitter.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/PMCEmitter.pm Sat May 16 10:35:31 2009 (r38822)
+++ trunk/lib/Parrot/Pmc2c/PMCEmitter.pm Sat May 16 10:45:28 2009 (r38823)
@@ -619,8 +619,8 @@
my $flags = $self->vtable_flags;
$cout .= <<"EOC";
- Hash * isa_hash;
- VTABLE * vt = Parrot_${classname}_get_vtable(interp);
+ Hash *isa_hash = NULL;
+ VTABLE *vt = Parrot_${classname}_get_vtable(interp);
vt->base_type = $enum_name;
vt->flags = $flags;
vt->attribute_defs = attr_defs;
@@ -647,20 +647,26 @@
string_make(interp, " $provides", @{[length($provides) + 1]}, "ascii",
PObj_constant_FLAG|PObj_external_FLAG));
- /* set up isa hash */
- isa_hash = parrot_new_hash(interp);
- vt->isa_hash = isa_hash;
EOC
}
else {
$cout .= <<"EOC";
vt->whoami = CONST_STRING_GEN(interp, "$classname");
vt->provides_str = CONST_STRING_GEN(interp, "$provides");
+EOC
+ }
+
+ if (@isa) {
+ unshift @isa, $classname;
+ $cout .= <<"EOC";
- /* set up isa hash */
isa_hash = parrot_new_hash(interp);
vt->isa_hash = isa_hash;
EOC
+ } else {
+ $cout .= <<"EOC";
+ vt->isa_hash = NULL;
+EOC
}
for my $k ( keys %extra_vt ) {
@@ -683,7 +689,7 @@
interp->vtables[entry] = vt;
EOC
- for my $isa ($classname, @isa) {
+ for my $isa (@isa) {
$cout .= <<"EOC";
parrot_hash_put(interp, isa_hash, (void *)(CONST_STRING_GEN(interp, "$isa")), PMCNULL);
EOC
@@ -729,7 +735,8 @@
EOC
- for my $isa ($classname, @isa) {
+ @isa = $classname unless @isa;
+ for my $isa (@isa) {
$cout .= <<"EOC";
VTABLE_push_string(interp, mro, CONST_STRING_GEN(interp, "$isa"));
EOC
Modified: trunk/src/pmc/default.pmc
==============================================================================
--- trunk/src/pmc/default.pmc Sat May 16 10:35:31 2009 (r38822)
+++ trunk/src/pmc/default.pmc Sat May 16 10:45:28 2009 (r38823)
@@ -896,12 +896,19 @@
*/
VTABLE INTVAL isa_pmc(PMC *lookup) {
+ Hash *isa_hash = SELF->vtable->isa_hash;
+ STRING *pmc_name;
+
if (PMC_IS_NULL(lookup))
return 0;
+ pmc_name = VTABLE_get_string(interp, lookup);
+
+ if (!isa_hash)
+ return Parrot_str_equal(interp, SELF->vtable->whoami, pmc_name);
+
/* RT #46665 - walk mro */
- return parrot_hash_exists(INTERP, SELF->vtable->isa_hash,
- (void *)VTABLE_get_string(interp, lookup));
+ return parrot_hash_exists(INTERP, isa_hash, (void *)pmc_name);
}
/*
@@ -918,6 +925,9 @@
VTABLE INTVAL isa(STRING *_class) {
/* RT #46665 - walk mro */
+ if (!SELF->vtable->isa_hash)
+ return Parrot_str_equal(interp, SELF->vtable->whoami, _class);
+
return parrot_hash_exists(INTERP, SELF->vtable->isa_hash,
(void *)_class);
}
Modified: trunk/src/pmc/pmcproxy.pmc
==============================================================================
--- trunk/src/pmc/pmcproxy.pmc Sat May 16 10:35:31 2009 (r38822)
+++ trunk/src/pmc/pmcproxy.pmc Sat May 16 10:45:28 2009 (r38823)
@@ -295,9 +295,16 @@
return 1;
/* Look in the isa hash. */
- if (interp->vtables[_proxy->id] != NULL &&
- parrot_hash_exists(interp, interp->vtables[_proxy->id]->isa_hash, classname))
- return 1;
+ if (interp->vtables[_proxy->id]) {
+ Hash *isa_hash = interp->vtables[_proxy->id]->isa_hash;
+
+ if (!isa_hash && Parrot_str_equal(interp,
+ interp->vtables[_proxy->id]->whoami, classname))
+ return 1;
+
+ if (isa_hash && parrot_hash_exists(interp, isa_hash, classname))
+ return 1;
+ }
/* Iterate over all the parents and check if they respond true
* for 'isa' on the original comparison. */
@@ -334,9 +341,17 @@
return 1;
/* Look in the isa hash. */
- if (interp->vtables[_proxy->id] != NULL &&
- parrot_hash_exists(interp, interp->vtables[_proxy->id]->isa_hash, classname))
- return 1;
+ if (interp->vtables[_proxy->id]) {
+ Hash *isa_hash = interp->vtables[_proxy->id]->isa_hash;
+
+ if (!isa_hash && Parrot_str_equal(interp,
+ interp->vtables[_proxy->id]->whoami, classname)) {
+ return 1;
+ }
+
+ if (isa_hash && parrot_hash_exists(interp, isa_hash, classname))
+ return 1;
+ }
return 0;
}
More information about the parrot-commits
mailing list