Skip to content

Commit

Permalink
perf(core): Don't waste time instantiating unused intermediaries
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Jan 4, 2020
1 parent 6dff532 commit 6f3dba1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
9 changes: 4 additions & 5 deletions core/length.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 87,11 @@ return pl.class({
end,

__add = function (self, other)
local result = SILE.length(self)
if type(self) == "number" then self, other = other, self end
other = SU.cast("length", other)
result.length = result.length other.length
result.stretch = result.stretch other.stretch
result.shrink = result.shrink other.shrink
return result
return SILE.length(self.length other.length,
self.stretch other.stretch,
self.shrink other.shrink)
end,

__sub = function (self, other)
Expand Down
8 changes: 4 additions & 4 deletions core/measurement.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 58,17 @@ local measurement = pl.class({
end,

absolute = function (self)
local def = SILE.units[self.unit]
local amount = def.converter and def.converter(self.amount) or self.amount * def.value
return SILE.measurement(amount)
return SILE.measurement(self:tonumber())
end,

tostring = function (self)
return self:__tostring()
end,

tonumber = function (self)
return self:absolute().amount
local def = SILE.units[self.unit]
local amount = def.converter and def.converter(self.amount) or self.amount * def.value
return amount
end,

__tostring = function (self)
Expand Down

0 comments on commit 6f3dba1

Please sign in to comment.