Skip to content

Commit

Permalink
Dont defer tokenization of macro body
Browse files Browse the repository at this point in the history
  • Loading branch information
brucemiller committed Jul 2, 2023
1 parent eb778a2 commit a272807
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions lib/LaTeXML/Core/Definition/Expandable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ sub new {
# rescan for match tokens and unwrap dont_expand...
$expansion = $expansion->packParameters unless $traits{nopackParameters};
}
elsif (!ref $expansion) {
$expansion = TokenizeInternal($expansion)->packParameters; }

return bless { cs => $cs, parameters => $parameters, expansion => $expansion,
locator => $source->getLocator,
isProtected => $traits{protected} || $STATE->getPrefix('protected'),
Expand All @@ -45,13 +48,7 @@ sub isExpandable {

sub getExpansion {
my ($self) = @_;
my $expansion = $$self{expansion};
if (!ref $expansion) { # Tokenization DEFERRED till actually used (shaves > 5%)
$expansion = TokenizeInternal($expansion);
# rescan for match tokens and unwrap dont_expand...
$expansion = $expansion->packParameters;
$$self{expansion} = $expansion; }
return $expansion; }
return $$self{expansion}; }

# Expand the expandable control sequence. This should be carried out by the Gullet.
sub invoke {
Expand All @@ -60,14 +57,13 @@ sub invoke {
# shortcut for "trivial" macros; but only if not tracing & profiling!!!!
my $tracing = $STATE->lookupValue('TRACINGMACROS');
my $profiled = $STATE->lookupValue('PROFILING') && ($LaTeXML::CURRENT_TOKEN || $$self{cs});
my $expansion = $self->getExpansion;
my $expansion = $$self{expansion};
my $etype = ref $expansion;
my $iscode = $etype eq 'CODE';
my $result;
my $parms = $$self{parameters};

LaTeXML::Core::Definition::startProfiling($profiled, 'expand') if $profiled;
if ($iscode) {
if ($etype eq 'CODE') {
# Harder to emulate \tracingmacros here.
my @args = ($parms ? $parms->readArguments($gullet, $self) : ());
$result = Tokens(&$expansion($gullet, @args));
Expand Down Expand Up @@ -113,7 +109,7 @@ sub equals {
my ($self, $other) = @_;
return (defined $other && (ref $self) eq (ref $other))
&& Equals($self->getParameters, $other->getParameters)
&& Equals($self->getExpansion, $other->getExpansion); }
&& Equals($$self{expansion}, $$other{expansion}); }

#======================================================================
1;
Expand Down

0 comments on commit a272807

Please sign in to comment.