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
This commit is contained in:
rxi 2014-03-05 12:41:40 +00:00
parent 2699094218
commit 83a051aadb

View File

@ -11,7 +11,7 @@ local lume = { _version = "1.1.0" }
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