Skip to content

Instantly share code, notes, and snippets.

@mlschroe
Created September 13, 2011 16:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mlschroe/1214298 to your computer and use it in GitHub Desktop.
Save mlschroe/1214298 to your computer and use it in GitHub Desktop.
diff --git a/src/Perl6/Metamodel/C3MRO.pm b/src/Perl6/Metamodel/C3MRO.pm
index 6889829..fd2b170 100644
--- a/src/Perl6/Metamodel/C3MRO.pm
+++ b/src/Perl6/Metamodel/C3MRO.pm
@@ -9,14 +9,18 @@ role Perl6::Metamodel::C3MRO {
# Provided we have immediate parents...
my @result;
if +@immediate_parents {
- # Build merge list of lineraizations of all our parents, add
- # immediate parents and merge.
- my @merge_list;
- for @immediate_parents {
- @merge_list.push(self.compute_mro($_));
+ if +@immediate_parents == 1 {
+ @result := nqp::clone(@immediate_parents[0].HOW.mro(@immediate_parents[0]));
+ } else {
+ # Build merge list of lineraizations of all our parents, add
+ # immediate parents and merge.
+ my @merge_list;
+ for @immediate_parents {
+ @merge_list.push($_.HOW.mro($_));
+ }
+ @merge_list.push(@immediate_parents);
+ @result := c3_merge(@merge_list);
}
- @merge_list.push(@immediate_parents);
- @result := c3_merge(@merge_list);
}
# Put this class on the start of the list, and we're done.
diff --git a/src/Perl6/Metamodel/MROBasedMethodDispatch.pm b/src/Perl6/Metamodel/MROBasedMethodDispatch.pm
index ad330eb..50d021a 100644
--- a/src/Perl6/Metamodel/MROBasedMethodDispatch.pm
+++ b/src/Perl6/Metamodel/MROBasedMethodDispatch.pm
@@ -22,12 +22,14 @@ role Perl6::Metamodel::MROBasedMethodDispatch {
# Walk MRO and add methods to cache, unless another method
# lower in the class hierarchy "shadowed" it.
my %cache;
+ my @mro_reversed;
for self.mro($obj) {
+ @mro_reversed.unshift($_);
+ }
+ for @mro_reversed {
my %methods := $_.HOW.method_table($_);
for %methods {
- unless %cache{$_.key} {
- %cache{$_.key} := $_.value;
- }
+ %cache{$_.key} := $_.value;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment