Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Minor optimization to BUILDALL and .can. Takes 10s or so off the spec…
…test run for me.
  • Loading branch information
jnthn committed Feb 24, 2010
1 parent 3b44842 commit 90b5153
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 15 deletions.
26 changes: 15 additions & 11 deletions src/builtins/Mu.pir
Expand Up @@ -167,13 +167,18 @@ like this.
.param pmc attrinit
.param pmc posargs
.local int num_pos_args
.local int cur_pos_arg
num_pos_args = elements posargs
.include 'iterator.pasm'
.local pmc p6meta, parents, it
.local pmc p6meta, parents, it, build_method
p6meta = get_hll_global ['Mu'], '$!P6META'
$P0 = p6meta.'get_parrotclass'(self)
parents = inspect $P0, 'all_parents'
it = iter parents
set it, .ITERATE_FROM_END
parents_loop:
# Loop through all of the parent classes, in reverse mro.
# For each parent class, call its BUILD method with the
Expand All @@ -185,27 +190,26 @@ like this.
.local pmc parentproto
$P0 = getprop 'metaclass', $P0
parentproto = $P0.'WHAT'()
$I0 = can parentproto, 'BUILD'
unless $I0 goto parents_loop
build_method = find_method_null_ok parentproto, 'BUILD'
if null build_method goto parents_loop
.lex '$CLASS', parentproto
# Look through posargs for a corresponding protoobject
# with a WHENCE property. If found, that WHENCE property
# is used as the arguments to the parent class BUILD.
.local pmc pos_it, argproto
pos_it = iter posargs
.local pmc argproto
cur_pos_arg = 0
posargs_loop:
unless pos_it goto posargs_done
argproto = shift pos_it
if cur_pos_arg >= num_pos_args goto posargs_done
argproto = posargs[cur_pos_arg]
inc cur_pos_arg
$P1 = argproto.'HOW'()
ne_addr $P0, $P1, posargs_loop
$P0 = argproto.'WHENCE'()
if null $P0 goto posargs_done
$P1 = find_method parentproto, 'BUILD'
$P1(candidate, $P0 :flat :named)
build_method(candidate, $P0 :flat :named)
goto parents_loop
posargs_done:
$P1 = find_method parentproto, 'BUILD'
$P1(candidate, attrinit :flat :named)
build_method(candidate, attrinit :flat :named)
goto parents_loop
parents_done:
.return (candidate)
Expand Down
6 changes: 2 additions & 4 deletions src/metamodel/ClassHOW.pir
Expand Up @@ -327,12 +327,10 @@ Completes the creation of the metaclass and return a proto-object.
.sub 'can' :method
.param pmc obj
.param string name
push_eh not_found
$P0 = find_method obj, name
pop_eh
$P0 = find_method_null_ok obj, name
if null $P0 goto not_found
.return ($P0)
not_found:
pop_eh
$P0 = get_hll_global '&Nil'
.tailcall $P0()
.end
Expand Down
16 changes: 16 additions & 0 deletions src/ops/perl6.ops
Expand Up @@ -703,6 +703,22 @@ inline op x_setprophash(in PMC, in PMC) :base_core {
goto NEXT();
}


/*

=item find_method_null_ok(out PMC, in PMC, in STR)

Like Parrot's find_method, but returns PMCNULL in $1 if $2 doesn't have a
method named $3 instead of throwing an exception.

=cut

*/
inline op find_method_null_ok(out PMC, in PMC, in STR) :base_core {
$1 = VTABLE_find_method(interp, $2, $3);
goto NEXT();
}

/*
* Local variables:
* c-file-style: "parrot"
Expand Down

0 comments on commit 90b5153

Please sign in to comment.