Skip to content

Commit

Permalink
Use combined TRACING control to minimize lookups
Browse files Browse the repository at this point in the history
  • Loading branch information
brucemiller committed Jul 2, 2023
1 parent 7b57b78 commit 5c052ec
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 18 deletions.
6 changes: 3 additions & 3 deletions lib/LaTeXML/Core/Definition/Conditional.pm
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ sub invoke_conditional {
my $parms = $$self{parameters};
my @args = ($parms ? $parms->readArguments($gullet) : ());
$$LaTeXML::IFFRAME{parsing} = 0; # Now, we're done parsing the Test clause.
my $tracing = $STATE->lookupValue('TRACINGCOMMANDS') || $LaTeXML::DEBUG{tracing};
my $tracing = ($STATE->lookupValue('TRACING') || 0) & 2;
if ($tracing) {
Debug('{' . $self->tracingCSName . "} [#$ifid]");
Debug($self->tracingArgs(@args)) if @args; }
Expand Down Expand Up @@ -169,7 +169,7 @@ sub invoke_else {
Debug('{' . ToString($LaTeXML::CURRENT_TOKEN) . '}'
. " [for " . ToString($$LaTeXML::IFFRAME{token}) . " #" . $$LaTeXML::IFFRAME{ifid}
. " skipping to " . ToString($t) . "]")
if $STATE->lookupValue('TRACINGCOMMANDS') || $LaTeXML::DEBUG{tracing};
if ($STATE->lookupValue('TRACING') || 0) & 2;
return; } }

sub invoke_fi {
Expand All @@ -187,7 +187,7 @@ sub invoke_fi {
$STATE->shiftValue('if_stack'); # Done with this frame
Debug('{' . ToString($LaTeXML::CURRENT_TOKEN) . '}'
. " [for " . Stringify($$LaTeXML::IFFRAME{token}) . " #" . $$LaTeXML::IFFRAME{ifid} . "]")
if $STATE->lookupValue('TRACINGCOMMANDS') || $LaTeXML::DEBUG{tracing};
if ($STATE->lookupValue('TRACING') || 0) & 2;
return; } }

sub equals {
Expand Down
6 changes: 4 additions & 2 deletions lib/LaTeXML/Core/Definition/Constructor.pm
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,10 @@ sub getNumArgs {
sub invoke {
my ($self, $stomach) = @_;
# Call any `Before' code.
my $profiled = $STATE->lookupValue('PROFILING') && ($LaTeXML::CURRENT_TOKEN || $$self{cs});
my $tracing = $STATE->lookupValue('TRACINGCOMMANDS') || $LaTeXML::DEBUG{tracing};
my $_tracing = $STATE->lookupValue('TRACING') || 0;
my $tracing = ($_tracing & 2);
my $profiled = ($_tracing & 4) && ($LaTeXML::CURRENT_TOKEN || $$self{cs});

LaTeXML::Core::Definition::startProfiling($profiled, 'digest') if $profiled;

my @pre = $self->executeBeforeDigest($stomach);
Expand Down
16 changes: 8 additions & 8 deletions lib/LaTeXML/Core/Definition/Expandable.pm
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ sub invoke {
no warnings 'recursion';
my ($self, $gullet, $onceonly) = @_;
# 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 $_tracing = $STATE->lookupValue('TRACING') || 0;
my $tracing = ($_tracing & 1);
my $profiled = ($_tracing & 4) && ($LaTeXML::CURRENT_TOKEN || $$self{cs});
my $etype = ref $expansion;
my $iscode = $etype eq 'CODE';
my $result;
Expand All @@ -71,12 +72,11 @@ sub invoke {
# Harder to emulate \tracingmacros here.
my @args = ($parms ? $parms->readArguments($gullet, $self) : ());
$result = Tokens(&$expansion($gullet, @args));
if ($tracing || $LaTeXML::DEBUG{tracing}) { # More involved...
if ($tracing) {
Debug($self->tracingCSName . ' ==> ' . tracetoString($result));
Debug($self->tracingArgs(@args)) if @args; } }
elsif (!$$self{parameters}) { # Trivial macro
Debug($self->tracingCSName . ' ->' . tracetoString($expansion))
if $tracing || $LaTeXML::DEBUG{tracing};
elsif (!$parms) { # Trivial macro
Debug($self->tracingCSName . ' ->' . tracetoString($expansion)) if $tracing;
# For trivial expansion, make sure we don't get \cs or \relax\cs direct recursion!
if (!$onceonly && $$self{cs}) {
my ($t0, $t1) = ($etype eq 'LaTeXML::Core::Tokens'
Expand All @@ -89,13 +89,13 @@ sub invoke {
$expansion = Tokens(); } }
$result = $expansion; }
else {
my @args = ($parms ? $parms->readArguments($gullet, $self) : ());
my @args = $parms->readArguments($gullet, $self);
# for "real" macros, make sure all args are Tokens
my $r;
my @targs = map { ($_ && ($r = ref $_)
&& (($r eq 'LaTeXML::Core::Token') || ($r eq 'LaTeXML::Core::Tokens'))
? $_ : Tokens(Revert($_))); } @args;
if ($tracing || $LaTeXML::DEBUG{tracing}) { # More involved...
if ($tracing) { # More involved...
Debug($self->tracingCSName . ' ->' . tracetoString($expansion));
Debug($self->tracingArgs(@targs)) if @args; }
$result = $expansion->substituteParameters(@targs); }
Expand Down
6 changes: 4 additions & 2 deletions lib/LaTeXML/Core/Definition/Primitive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,10 @@ sub executeAfterDigest {
# Digest the primitive; this should occur in the stomach.
sub invoke {
my ($self, $stomach) = @_;
my $profiled = $STATE->lookupValue('PROFILING') && ($LaTeXML::CURRENT_TOKEN || $$self{cs});
my $tracing = $STATE->lookupValue('TRACINGCOMMANDS') || $LaTeXML::DEBUG{tracing};
my $_tracing = $STATE->lookupValue('TRACING') || 0;
my $tracing = ($_tracing & 2); # tracing commands
my $profiled = ($_tracing & 4) && ($LaTeXML::CURRENT_TOKEN || $$self{cs});

LaTeXML::Core::Definition::startProfiling($profiled, 'digest') if $profiled;
Debug('{' . $self->tracingCSName . '}') if $tracing;
my @result = ($self->executeBeforeDigest($stomach));
Expand Down
5 changes: 3 additions & 2 deletions lib/LaTeXML/Core/Definition/Register.pm
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ sub valueOf {

sub setValue {
my ($self, $value, $scope, @args) = @_;
my $tracing = $STATE->lookupValue('TRACINGCOMMANDS') || $LaTeXML::DEBUG{tracing};
my $tracing = (($STATE->lookupValue('TRACING') || 0) & 2); # tracing commands
if ($tracing) {
my $scope = $STATE->getPrefix('global') ? 'globally ' : '';
my $csname = ToString($$self{cs});
Expand Down Expand Up @@ -96,7 +96,8 @@ sub addValue {
# (other than afterassign)
sub invoke {
my ($self, $stomach) = @_;
my $profiled = $STATE->lookupValue('PROFILING') && ($LaTeXML::CURRENT_TOKEN || $$self{cs});
my $_tracing = $STATE->lookupValue('TRACING') || 0;
my $profiled = ($_tracing & 4) && ($LaTeXML::CURRENT_TOKEN || $$self{cs});
LaTeXML::Core::Definition::startProfiling($profiled, 'digest') if $profiled;

my $gullet = $stomach->getGullet;
Expand Down
2 changes: 1 addition & 1 deletion lib/LaTeXML/Core/Whatsit.pm
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ sub beAbsorbed {
"Whatsit absorb limit of $LaTeXML::ABSORB_LIMIT exceeded, infinite loop?"); } }

my $defn = $self->getDefinition;
my $profiled = $STATE->lookupValue('PROFILING') && $defn->getCS;
my $profiled = (($STATE->lookupValue('TRACING') || 0) & 4) && $defn->getCS;
LaTeXML::Core::Definition::startProfiling($profiled, 'absorb') if $profiled;
my @result = $defn->doAbsorbtion($document, $self);
LaTeXML::Core::Definition::stopProfiling($profiled, 'absorb') if $profiled;
Expand Down

0 comments on commit 5c052ec

Please sign in to comment.