Explorar o código

Optimization for 'n^2'

Squares are much more common than other exponentiations, and 'n*n' is
much more efficient than 'pow'.
Roberto Ierusalimschy %!s(int64=4) %!d(string=hai) anos
pai
achega
9d067ab73b
Modificáronse 1 ficheiros con 2 adicións e 1 borrados
  1. 2 1
      llimits.h

+ 2 - 1
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 */