Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[v6] Use a dedicated array for line number memos

  • Loading branch information...
commit abd12f02c5d77ca6565029900c8492183292bf9e 1 parent 191bfbf
@sorear authored
Showing with 18 additions and 6 deletions.
  1. +18 −6 v6/tryfile
View
24 v6/tryfile
@@ -195,6 +195,18 @@ package Niecza {
augment class STD {
+method lineof ($p) {
+ return 1 unless defined $p;
+ my $line = @*LINEMEMOS[$p];
+ return $line if $line;
+ $line = 1; my $pos = 0;
+ my $lm = @*LINEMEMOS;
+ self.orig ~~ / :r [ \n { $lm[$pos++] = $line++ } ||
+ . { $lm[$pos++] = $line } ]* /;
+ $lm[$pos++] = $line;
+ return $lm[$p] // 0;
+}
+
our $ALL;
method getsig {
my $pv = $*CURLEX.{'%?PLACEHOLDERS'};
@@ -237,8 +249,7 @@ method getsig {
}
token ws {
:my $startpos = Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {self}))))) };
- :my $startmemo = @*MEMOS[$startpos];
- :my $stub = return self if $startmemo<ws> :exists; #OK
+ :my $stub = return self if @*MEMOS[$startpos]<ws> :exists; #OK
:dba('whitespace')
\h+ <![\#\s\\]> { @*MEMOS[ Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {$¢}))))) } ]<ws> = $startpos; } # common case
@@ -257,13 +268,13 @@ token ws {
# top level separator.
{
my $pos = Q:CgOp { (box Num (cast num (cursor_pos (cast cursor (@ {$¢}))))) };
- my $memo = @*MEMOS[$pos];
if ($pos == $startpos) {
- $memo<ws>:delete;
+ @*MEMOS[$pos]<ws>:delete;
}
else {
- $memo<ws> = $startpos;
- $memo<endstmt> = $startmemo<endstmt> if $startmemo<endstmt> :exists;
+ @*MEMOS[$pos]<ws> = $startpos;
+ @*MEMOS[$pos]<endstmt> = @*MEMOS[$startpos]<endstmt>
+ if @*MEMOS[$startpos]<endstmt> :exists;
}
}
}
@@ -346,6 +357,7 @@ augment class Cursor {
sub compiler(:$filename, :$text, :$settingname, :$niecza) {
my $*SETTINGNAME = $settingname;
my @*MEMOS;
+ my @*LINEMEMOS;
my $*FILE = { name => $filename };
my @*ACTIVE;
my $*HIGHWATER = 0;
Please sign in to comment.
Something went wrong with that request. Please try again.