Jelajahi Sumber

Optimization for 'n^2'

Squares are much more common than other exponentiations, and 'n*n' is
much more efficient than 'pow'.
Roberto Ierusalimschy 4 tahun lalu
induk
melakukan
9d067ab73b
1 mengubah file dengan 2 tambahan dan 1 penghapusan
  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 */