5 Commits

Author SHA1 Message Date
rxi
e6d47627cd Increased version to 1.1.1 2014-03-05 21:52:28 +00:00
rxi
05828bd840 Fixed module's table not updating in lume.hotswap()
Changed the returned values from pcall() in lume.hotswap() to be handled
correctly -- the second return value being the wrapped-function's first
return value. This bug would effect hotswapped modules which used the
modern approach of returning a table rather than creating globals.
2014-03-05 19:11:14 +00:00
rxi
83a051aadb Improved lume.clamp()'s performance on non-JIT
Removed use of the functions math.max() and math.min() and replaced them
with and/ors:

[5000000 calls, Lua5.2]
old func: 1.37 seconds
new func: 0.53 seconds
2014-03-05 12:44:19 +00:00
rxi
2699094218 Added better tests for lume.distance() 2014-03-05 12:22:05 +00:00
rxi
a08436445d Improved lume.distance()'s performance on non-JIT
Replaced use of the exponent operator with multiplications, yielding a
performance increase on non-JIT Lua:

[5000000 calls, Lua 5.1]
old func: 2.03 seconds
new func: 1.17 seconds

[5000000 calls, Lua 5.2]
old func: 1.60 seconds
new func: 0.89 seconds

[2000000000 calls, LuaJIT 2.0.2]
old func: 0.89 seconds
new func: 0.89 seconds
2014-03-05 12:18:49 +00:00
2 changed files with 12 additions and 10 deletions

View File

@@ -7,11 +7,11 @@
-- under the terms of the MIT license. See LICENSE for details.
--
local lume = { _version = "1.1.0" }
local lume = { _version = "1.1.1" }
function lume.clamp(x, min, max)
return math.max(math.min(x, max), min)
return x < min and min or (x > max and max or x)
end
@@ -43,7 +43,9 @@ end
function lume.distance(x1, y1, x2, y2, squared)
local s = (x1 - x2) ^ 2 + (y1 - y2) ^ 2
local dx = x1 - x2
local dy = y1 - y2
local s = dx * dx + dy * dy
return squared and s or math.sqrt(s)
end
@@ -264,12 +266,13 @@ function lume.hotswap(modname)
if type(v) == "table" then update(old[k], v) else old[k] = v end
end
end
local oldmod = pcall(require, modname) or nil
local err = nil
local function onerror(e)
for k, v in pairs(_G) do _G[k] = oldglobal[k] end
err = lume.trim(e)
end
local ok, oldmod = pcall(require, modname)
oldmod = ok and oldmod or nil
xpcall(function()
package.loaded[modname] = nil
local newmod = require(modname)

View File

@@ -64,11 +64,11 @@ end
-- lume.distance
tests["lume.distance"] = function()
testeq( lume.distance(10, 20, 10, 20), 0 )
testeq( lume.distance(10, 20, 20, 20), 10 )
local x = lume.distance(1, 2, 5, 7)
testeq( lume.distance(1, 2, 5, 7, true), x * x )
testeq( lume.distance(10, 10, 10, 20, true), 10 * 10 )
testeq( lume.distance(15, 20, 15, 20), 0 )
testeq( lume.distance(13, 44, 156, 232), 236.205419074 )
testeq( lume.distance(-23, 66, -232, 123), 216.633330769 )
local x = lume.distance(13, 15, -2, 81)
testeq( lume.distance(13, 15, -2, 81, true), x * x )
end
-- lume.angle
@@ -103,7 +103,6 @@ tests["lume.shuffle"] = function()
testeq( lume.shuffle({}), {} )
end
-- lume.array
tests["lume.array"] = function()
local t = lume.array(pairs({a=0, b=0, c=0}))