Skip to content

Commit

Permalink
Optimization for 'n^2'
Browse files Browse the repository at this point in the history
Squares are much more common than other exponentiations, and 'n*n' is
much more efficient than 'pow'.
  • Loading branch information
roberto-ieru committed Nov 13, 2020
1 parent 2f4162b commit 9d067ab
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion llimits.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down

0 comments on commit 9d067ab

Please sign in to comment.