Skip to content

Commit 41e1fd8

Browse files
committed
Make check for if we're in precompilation mode cheaper. Saves walking a load of call frames if we're quite deep in the parse, though probably only a small saving overall.
1 parent abbaf88 commit 41e1fd8

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/HLL/SerializationContextBuilder.pm

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ class HLL::Compiler::SerializationContextBuilder {
5757
# Other SCs that we are dependent on (maps handle to SC).
5858
has %!dependencies;
5959

60+
# Whether we're in pre-compilation mode.
61+
has $!precomp_mode;
62+
6063
method new(:$handle!, :$description = '<unknown>') {
6164
my $obj := self.CREATE();
6265
$obj.BUILD(:handle($handle), :description($description));
@@ -69,6 +72,7 @@ class HLL::Compiler::SerializationContextBuilder {
6972
%!addr_to_slot := pir::new('Hash');
7073
@!event_stream := pir::new('ResizablePMCArray');
7174
$!sc.set_description($description);
75+
$!precomp_mode := %*COMPILING<%?OPTIONS><target> eq 'pir';
7276
}
7377

7478
# Gets the slot for a given object. Dies if it is not in the context.
@@ -133,14 +137,14 @@ class HLL::Compiler::SerializationContextBuilder {
133137

134138
# Checks if we are in pre-compilation mode.
135139
method is_precompilation_mode() {
136-
%*COMPILING<%?OPTIONS><target> eq 'pir'
140+
$!precomp_mode
137141
}
138142

139143
# Add an event that may have an action to deserialize or fix up.
140144
# Note that we can determine which one we need and just save the
141145
# needed one.
142146
method add_event(:$deserialize_past, :$fixup_past) {
143-
if self.is_precompilation_mode() {
147+
if $!precomp_mode {
144148
# Pre-compilation; only need deserialization PAST.
145149
@!event_stream.push(Event.new(:deserialize_past($deserialize_past)));
146150
}

0 commit comments

Comments
 (0)