Changeset 22861 for src

Show
Ignore:
Timestamp:
11/03/08 21:02:45 (2 months ago)
Author:
azawawi
Message:

[redspans] trees are now stored as action refs thus consuming far less memory.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/perl6/redspans

    r22819 r22861  
    2828        say("Undefined $i"),next unless defined $loc[$i]; 
    2929        my $c = substr($txt,$i,1); 
    30         my $tree = "@{$loc[$i]}"; 
     30        my $tree = ""; 
     31        for my $action_ref (@{$loc[$i]}) { 
     32            $tree .= ${$action_ref} . " "; 
     33        } 
    3134        if($tree ne $last_tree) { 
    3235            say "\n'$buffer'\n$last_tree" if $buffer ne ''; 
     
    4447 
    4548    our $AUTOLOAD; 
    46  
     49    my %actions = (); 
    4750    sub AUTOLOAD { 
    48         my $self = shift; 
    49         my $C = shift; 
    50         my $F = $C->{_from}; 
    51         my $P = $C->{_pos}; 
    52         $AUTOLOAD =~ s/^Actions:://; 
    53         $loc[$P] = [] if $loc[$P];      # in case we backtracked to here 
    54         for ($F..$P-1) { 
    55             unshift @{$loc[$_]}, $AUTOLOAD; 
    56         } 
     51        my $self = shift; 
     52        my $C = shift; 
     53        my $F = $C->{_from}; 
     54        my $P = $C->{_pos}; 
     55        $AUTOLOAD =~ s/^Actions:://; 
     56        $loc[$P] = [] if $loc[$P];      # in case we backtracked to here 
     57        my $action = $AUTOLOAD; 
     58        my $action_ref = $actions{$action}; 
     59        if(!$action_ref) { 
     60            $actions{$action} = $action_ref = \$action; 
     61        } 
     62        for ($F..$P-1) { 
     63            unshift @{$loc[$_]}, $action_ref; 
     64        } 
    5765    } 
    5866