Skip to content

Commit

Permalink
perf(utilities): Leave tostring() casting to after debug invocations,…
Browse files Browse the repository at this point in the history
… not before
  • Loading branch information
alerque committed Feb 8, 2024
1 parent da80c56 commit 72965ad
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 24 deletions.
2 changes: 1 addition & 1 deletion classes/base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ end

function class:runHooks (category, options)
for _, func in ipairs(self.hooks[category]) do
SU.debug("classhooks", "Running hook from", category, options and "with options " .. #options)
SU.debug("classhooks", "Running hook from", category, options and "with options #" .. #options)
func(self, options)
end
end
Expand Down
32 changes: 16 additions & 16 deletions core/break.lua
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ function lineBreak:tryBreak() -- 855
if not node then pi = ejectPenalty; breakType = "hyphenated"
elseif node.is_discretionary then breakType = "hyphenated"; pi = param("hyphenPenalty")
else breakType = "unhyphenated"; pi = node.penalty or 0 end
if debugging then SU.debug("break", "Trying a ", breakType, "break p =", pi) end
if debugging then SU.debug("break", "Trying a", breakType, "break p =", pi) end
self.no_break_yet = true -- We have to store all this state crap in the object, or it's global variables all the way
self.prev_prev_r = nil
self.prev_r = self.activeListHead
Expand All @@ -176,7 +176,7 @@ function lineBreak:tryBreak() -- 855
end
-- 861
if self.r.lineNumber > self.old_l then
if debugging then SU.debug("break", "Minimum demerits = " .. self.minimumDemerits) end
if debugging then SU.debug("break", "Minimum demerits =", self.minimumDemerits) end
if self.minimumDemerits < awful_bad and (self.old_l ~= self.easy_line or self.r == self.activeListHead) then
self:createNewActiveNodes(breakType)
end
Expand All @@ -199,16 +199,16 @@ function lineBreak:tryBreak() -- 855
self.lineWidth = self.firstWidth
end
end
if debugging then SU.debug("break", "line width = " .. tostring(self.lineWidth)) end
if debugging then SU.debug("break", "line width =", self.lineWidth) end
end
if debugging then
SU.debug("break", " ---> (2) cuaw is " .. tostring(self.curActiveWidth))
SU.debug("break", " ---> aw is " .. tostring(self.activeWidth))
SU.debug("break", " ---> (2) cuaw is", self.curActiveWidth)
SU.debug("break", " ---> aw is", self.activeWidth)
end
self:considerDemerits(pi, breakType)
if debugging then
SU.debug("break", " <--- cuaw is " .. tostring(self.curActiveWidth))
SU.debug("break", " <--- aw is " .. tostring(self.activeWidth))
SU.debug("break", " <--- cuaw is", self.curActiveWidth)
SU.debug("break", " <--- aw is ", self.activeWidth)
end
end
end
Expand Down Expand Up @@ -269,7 +269,7 @@ function lineBreak:tryAlternatives(from, to)
local ss = shortfall - addWidth
-- Warning, assumes abosolute
local badness = SU.rateBadness(inf_bad, ss.length.amount, self.curActiveWidth[ss > 0 and "stretch" or "shrink"].length.amount)
if debugging then SU.debug("break", " badness of " .. ss .. " (" .. self.curActiveWidth .. ") is " .. badness) end
if debugging then SU.debug("break", " badness of", ss, "(", self.curActiveWidth, ") is", badness) end
if badness < localMinimum then
self.r.alternates = alternates
self.r.altSelections = combination
Expand All @@ -293,7 +293,7 @@ function lineBreak:considerDemerits(pi, breakType) -- 877
end
shortfall = self.lineWidth - self.curActiveWidth
self.badness, self.fitClass = fitclass(self, shortfall)
if debugging then SU.debug("break", self.badness .. " " .. self.fitClass) end
if debugging then SU.debug("break", self.badness, self.fitClass) end
if (self.badness > inf_bad or pi == ejectPenalty) then
if self.finalpass and self.minimumDemerits == awful_bad and self.r.next == self.activeListHead and self.prev_r == self.activeListHead then
self.artificialDemerits = true
Expand Down Expand Up @@ -382,11 +382,11 @@ function lineBreak:recordFeasible(pi, breakType) -- 881
local demerit = lineBreak:computeDemerits(pi, breakType)
if debugging then
if self.nodes[self.place] then
SU.debug("break", "@" .. self.nodes[self.place] .. " via @@" .. (self.r.serial or "0") .. " badness=" .. self.badness .. " demerit=".. demerit) -- 882
SU.debug("break", "@", self.nodes[self.place], "via @@", (self.r.serial or "0"), "badness =", self.badness, "demerit =", demerit) -- 882
else
SU.debug("break", "@ \\par via @@")
end
SU.debug("break", " fit class = "..self.fitClass)
SU.debug("break", " fit class =", self.fitClass)
end
demerit = demerit + self.r.totalDemerits
if demerit <= self.bestInClass[self.fitClass].minimalDemerits then
Expand Down Expand Up @@ -422,7 +422,7 @@ function lineBreak:createNewActiveNodes(breakType) -- 862
end
place = place + 1
end
if debugging then SU.debug("break", "Value of breakWidth = " .. tostring(self.breakWidth)) end
if debugging then SU.debug("break", "Value of breakWidth =", self.breakWidth) end
end
-- 869 (Add a new delta node)
if self.prev_r.type == "delta" then
Expand All @@ -432,7 +432,7 @@ function lineBreak:createNewActiveNodes(breakType) -- 862
self.activeWidth = SILE.types.length(self.breakWidth)
else
local newDelta = { next = self.r, type = "delta", width = self.breakWidth - self.curActiveWidth }
if debugging then SU.debug("break", "Added new delta node = " .. tostring(newDelta.width)) end
if debugging then SU.debug("break", "Added new delta node =", newDelta.width) end
self.prev_r.next = newDelta
self.prev_prev_r = self.prev_r
self.prev_r = newDelta
Expand All @@ -447,7 +447,7 @@ function lineBreak:createNewActiveNodes(breakType) -- 862
local class = classes[i]
local best = self.bestInClass[class]
local value = best.minimalDemerits
if debugging then SU.debug("break", "Class is "..class.." Best value here is " .. value) end
if debugging then SU.debug("break", "Class is", class, "Best value here is", value) end

if value <= self.minimumDemerits then
-- 871: this is what creates new active notes
Expand Down Expand Up @@ -489,7 +489,7 @@ function lineBreak.dumpBreakNode(_, node)
end

function lineBreak:describeBreakNode(node)
--print("@@" .. b.serial .. ": line " .. (b.lineNumber -1) .. "." .. b.fitness .. " " .. b.type .. " t=".. b.totalDemerits .. " -> @@ " .. (b.prevBreak and b.prevBreak.serial or "0") )
--SU.debug("break", "@@", b.serial, ": line", b.lineNumber - 1, ".", b.fitness, b.type, "t=", b.totalDemerits, "-> @@", b.prevBreak and b.prevBreak.serial or "0")
if node.sentinel then return node.sentinel end
if node.type == "delta" then return "delta "..node.width.."pt" end
local before = self.nodes[node.curBreak-1]
Expand Down Expand Up @@ -582,7 +582,7 @@ function lineBreak:doBreak (nodes, hsize, sideways)
end
-- 889
while 1 do
if debugging then SU.debug("break", "@" .. self.pass .. "pass") end
if debugging then SU.debug("break", "@", self.pass, "pass") end
if self.threshold > inf_bad then self.threshold = inf_bad end
if self.pass == "second" then
self.nodes = SILE.hyphenate(self.nodes)
Expand Down
2 changes: 1 addition & 1 deletion core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ function settings:declare (spec)
SU.deprecated("'name' argument of SILE.settings:declare", "'parameter' argument of SILE.settings:declare", "0.10.10", "0.11.0")
end
if self.declarations[spec.parameter] then
SU.debug("settings", "Attempt to re-declare setting: " .. spec.parameter)
SU.debug("settings", "Attempt to re-declare setting:", spec.parameter)
return
end
self.declarations[spec.parameter] = spec
Expand Down
2 changes: 1 addition & 1 deletion core/utilities/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ utilities.debug = function (category, ...)
for i, input in ipairs(inputs) do
if type(input) == "function" then
local status, output = pcall(input)
inputs[i] = status and tostring(output) or SU.warn(("Output of %s debug function was an error: %s"):format(category, output))
inputs[i] = status and output or SU.warn(("Output of %s debug function was an error: %s"):format(category, output))
elseif type(input) ~= "string" then
inputs[i] = tostring(input)
end
Expand Down
2 changes: 1 addition & 1 deletion packages/math/base-elements.lua
Original file line number Diff line number Diff line change
Expand Up @@ -955,7 +955,7 @@ function elements.text:stretchyReshape (depth, height)
m = diff
end
end
SU.debug("math", "stretch: closestI =", tostring(closestI))
SU.debug("math", "stretch: closestI =", closestI)
if closest then
-- Now we have to re-shape the glyph chain. We will assume there
-- is only one glyph.
Expand Down
2 changes: 1 addition & 1 deletion pagebuilders/grid.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function pagebuilder.findBestBreak (_, options)
SU.debug("pagebuilder", "Page builder for frame", SILE.typesetter.frame.id, "called with", #vboxlist, "nodes,", target)
if SU.debugging("vboxes") then
for j, box in ipairs(vboxlist) do
SU.debug("vboxes", (j == i and " >" or " ") .. j .. ": " .. box)
SU.debug("vboxes", function () return (j == i and " >" or " ") .. j .. ": " .. box end)
end
end
while i < #vboxlist do
Expand Down
6 changes: 3 additions & 3 deletions typesetters/firstfit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,16 @@ function typesetter:breakIntoLines (nl, breakWidth)
local length = SILE.types.length()
for i = 1,#nl do local n = nl[i]
if n.is_box then
SU.debug("break", n .. " " .. tostring(n:lineContribution()))
SU.debug("break", n, function () return n:lineContribution() end)
length = length + n:lineContribution()
SU.debug("break", " Length now " .. tostring(length) .. " breakwidth ".. tostring(breakWidth))
SU.debug("break", " Length now ", length, "breakwidth", breakWidth)
end
if not n.is_box or n.isHangable then
SU.debug("break", n )
if n.is_glue then
length = length + n.width:absolute()
end
SU.debug("break", " Length now " .. tostring(length) .. " breakwidth " .. tostring(breakWidth))
SU.debug("break", " Length now ", length, " breakwidth ", breakWidth)
-- Can we break?
if length:tonumber() >= breakWidth:tonumber() then
SU.debug("break", "Breaking!")
Expand Down

0 comments on commit 72965ad

Please sign in to comment.