Optimization for 'n^2'

Squares are much more common than other exponentiations, and 'n*n' is
much more efficient than 'pow'.
This commit is contained in:
Roberto Ierusalimschy 2020-11-13 09:59:07 -03:00
parent 2f4162bc47
commit 9d067ab73b

View File

@ -326,7 +326,8 @@ typedef l_uint32 Instruction;
/* exponentiation */ /* exponentiation */
#if !defined(luai_numpow) #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 #endif
/* the others are quite standard operations */ /* the others are quite standard operations */