commit | 9d067ab73b6befa0a5418f1df35c711f6c6918b3 | [log] [tgz] |
---|---|---|
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | Fri Nov 13 09:59:07 2020 -0300 |
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | Fri Nov 13 09:59:07 2020 -0300 |
tree | 250093c32a8b0575c8c47aced1bdbb7d3d7bc3fd | |
parent | 2f4162bc473b995117e95c88230f637ca3e1c866 [diff] |
Optimization for 'n^2' Squares are much more common than other exponentiations, and 'n*n' is much more efficient than 'pow'.
diff --git a/llimits.h b/llimits.h index a76c13e..d039483 100644 --- a/llimits.h +++ b/llimits.h
@@ -326,7 +326,8 @@ /* 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 */