Skip to content

Commit

Permalink
RakuAST: Avoid DEPARSE during compilation for better performance
Browse files Browse the repository at this point in the history
DEPARSE can be surprisingly expensive, so when the compiler needs the
actual source string, just use the origin instead.
  • Loading branch information
niner committed Jun 4, 2023
1 parent 2c6c009 commit d320dee
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/Raku/ast/code.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -2007,7 +2007,7 @@ class RakuAST::RegexThunk
# Create Regex object.
my $regex := nqp::create(Regex);
nqp::bindattr($regex, Code, '$!signature', $signature);
nqp::bindattr_s($regex, Regex, '$!source', self.DEPARSE);
nqp::bindattr_s($regex, Regex, '$!source', self.origin.Str);
nqp::bindattr($signature, Signature, '$!code', $regex);
$regex
}
Expand Down
6 changes: 5 additions & 1 deletion src/Raku/ast/origins.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ class RakuAST::Origin {
method is-key() { nqp::isconcrete($!nestings) ?? True !! False }

method as-match() { $!source.match-from(self) }

method Str() {
nqp::substr($!source.orig, $!from, $!to - $!from)
}
}

# The class is supposed to mimic NQPMatch up to the level to make it usable as QAST::Node.node value.
Expand Down Expand Up @@ -192,4 +196,4 @@ class RakuAST::Origin::Source {
:line(@location[0]), :file(@location[2]),
:orig-line(self.original-line($from)))
}
}
}
4 changes: 2 additions & 2 deletions src/Raku/ast/statementprefixes.rakumod
Original file line number Diff line number Diff line change
Expand Up @@ -622,7 +622,7 @@ class RakuAST::StatementPrefix::Phaser::Pre
value => RakuAST::StrLiteral.new(
$condition
?? nqp::hllizefor($condition, 'Raku')
!! $blorst.DEPARSE
!! $blorst.origin.Str
)
)
)
Expand Down Expand Up @@ -691,7 +691,7 @@ class RakuAST::StatementPrefix::Phaser::Post
value => RakuAST::StrLiteral.new(
$condition
?? nqp::hllizefor($condition, 'Raku')
!! $blorst.DEPARSE
!! $blorst.origin.Str
)
)
)
Expand Down

0 comments on commit d320dee

Please sign in to comment.