Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Make boolification cheaper in cases where things don't override .Bool…
… and instead just rely on the definedness check.
  • Loading branch information
jnthn committed Oct 1, 2011
1 parent e32b7c2 commit 1c27dea
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Perl6/Metamodel/BoolificationProtocol.pm
@@ -1,6 +1,10 @@
role Perl6::Metamodel::BoolificationProtocol {
has $!boolification_mode;

method get_boolification_mode($obj) {
$!boolification_mode
}

method set_boolification_mode($obj, $mode) {
$!boolification_mode := $mode;
}
Expand Down
17 changes: 17 additions & 0 deletions src/Perl6/Metamodel/ClassHOW.pm
Expand Up @@ -88,6 +88,23 @@ class Perl6::Metamodel::ClassHOW

# Compose attributes.
self.compose_attributes($obj);

# See if we have a Bool method other than the one in the top type.
# If not, all it does is check if we have the type object.
unless self.get_boolification_mode($obj) != 0 {
my $i := 0;
my @mro := self.mro($obj);
while $i < +@mro {
my %meths := @mro[$i].HOW.method_table(@mro[$i]);
if pir::exists(%meths, 'Bool') {
last;
}
$i := $i + 1;
}
if $i + 1 == +@mro {
self.set_boolification_mode($obj, 5)
}
}

# Publish type and method caches.
self.publish_type_cache($obj);
Expand Down

0 comments on commit 1c27dea

Please sign in to comment.