From 83a051aadb23ff7805038da4e581d0d02bae0582 Mon Sep 17 00:00:00 2001 From: rxi Date: Wed, 5 Mar 2014 12:41:40 +0000 Subject: [PATCH] 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 --- lume.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lume.lua b/lume.lua index 3f8a501..61ab0c2 100644 --- a/lume.lua +++ b/lume.lua @@ -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