Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Do a little optimization to the deref_objectref dynop, and then elimi…
…nate the !DEREF PIR sub in favor of it. Wins a modest but worthwhile performance improvement.
  • Loading branch information
jnthn committed Jun 1, 2009
1 parent f43c644 commit def4e6d
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 28 deletions.
20 changes: 0 additions & 20 deletions src/builtins/guts.pir
Expand Up @@ -195,26 +195,6 @@ Helper function for implementing the VAR and .VAR macros.
.end
=item !DEREF
Helper function to dereference any chains
=cut
.sub '!DEREF'
.param pmc x
$P0 = get_root_namespace ['parrot';'ObjectRef']
$P0 = get_class $P0
loop:
$I0 = isa x, $P0
unless $I0 goto done
x = deref x
goto loop
done:
.return (x)
.end
=item !SAMETYPE_EXACT
Takes two types and returns true if they match exactly (not accounting for any
Expand Down
2 changes: 1 addition & 1 deletion src/builtins/op.pir
Expand Up @@ -84,7 +84,7 @@ src/builtins/op.pir - Perl 6 builtin operators

.sub 'postfix:++' :multi(Integer)
.param pmc a
$P0 = '!DEREF'(a)
$P0 = deref_objectref a
$P0 = clone $P0
.const 'Sub' $P1 = '!prefix:++Int'
$P1(a)
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Code.pir
Expand Up @@ -152,7 +152,7 @@ Gets the signature for the block, or returns Failure if it lacks one.
=cut

.sub 'signature' :method
$P0 = '!DEREF'(self)
$P0 = deref_objectref self
$P0 = getprop '$!signature', $P0
if null $P0 goto no_sig
.return ($P0)
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Object.pir
Expand Up @@ -35,7 +35,7 @@ like this.

# Make a clone.
.local pmc result
self = '!DEREF'(self)
self = deref_objectref self
result = clone self

# Set any new attributes.
Expand Down
2 changes: 1 addition & 1 deletion src/classes/Role.pir
Expand Up @@ -131,7 +131,7 @@ Checks if the given topic does the role.

# If the topic is the same as self, then we're done.
$I0 = 1
topic = '!DEREF'(topic)
topic = deref_objectref topic
eq_addr self, topic, done
$I0 = 0

Expand Down
4 changes: 2 additions & 2 deletions src/classes/Signature.pir
Expand Up @@ -401,13 +401,13 @@ lexicals as needed and performing type checks.
param_array:
$P0 = type.'ACCEPTS'(orig)
unless $P0 goto err_param_type_non_scalar
var = '!DEREF'(orig)
var = deref_objectref orig
var = '!CALLMETHOD'('Array', var)
goto param_val_done
param_hash:
$P0 = type.'ACCEPTS'(orig)
unless $P0 goto err_param_type_non_scalar
var = '!DEREF'(orig)
var = deref_objectref orig
var = '!CALLMETHOD'('Hash', var)
goto param_val_done
param_val_done:
Expand Down
10 changes: 8 additions & 2 deletions src/ops/perl6.ops
Expand Up @@ -11,6 +11,10 @@ VERSION = PARROT_VERSION;
# include <unicode/uchar.h>
#endif

/* We cache a couple of type IDs for an op that we hit on every method call. */
static INTVAL p6s_id = 0;
static INTVAL or_id = 0;

/*

=item rebless_subclass(in PMC, in PMC)
Expand Down Expand Up @@ -333,8 +337,10 @@ to the real underlying value.

*/
inline op deref_objectref(out PMC, in PMC) :base_core {
INTVAL p6s_id = pmc_type(interp, string_from_literal(interp, "Perl6Scalar"));
INTVAL or_id = pmc_type(interp, string_from_literal(interp, "ObjectRef"));
if (!p6s_id) {
p6s_id = pmc_type(interp, string_from_literal(interp, "Perl6Scalar"));
or_id = pmc_type(interp, string_from_literal(interp, "ObjectRef"));
}
$1 = $2;
while ($1->vtable->base_type == p6s_id || $1->vtable->base_type == or_id)
$1 = VTABLE_get_pmc(interp, $1);
Expand Down

0 comments on commit def4e6d

Please sign in to comment.