From 9d067ab73b6befa0a5418f1df35c711f6c6918b3 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 13 Nov 2020 09:59:07 -0300 Subject: Optimization for 'n^2' Squares are much more common than other exponentiations, and 'n*n' is much more efficient than 'pow'. --- llimits.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'llimits.h') diff --git a/llimits.h b/llimits.h index a76c13ed..d0394831 100644 --- a/llimits.h +++ b/llimits.h @@ -326,7 +326,8 @@ typedef l_uint32 Instruction; /* exponentiation */ #if !defined(luai_numpow) -#define luai_numpow(L,a,b) ((void)L, l_mathop(pow)(a,b)) +#define luai_numpow(L,a,b) \ + ((void)L, (b == 2) ? (a)*(a) : l_mathop(pow)(a,b)) #endif /* the others are quite standard operations */ -- cgit v1.2.3-55-g6feb