View Single Post
11/24/14, 04:39 PM   #16
circonian
AddOn Author - Click to view addons
Join Date: May 2014
Posts: 613
Originally Posted by Sasky View Post
The IF would return true as long as v isn't NIL or boolean false. If it's NIL, it shouldn't even be iterated over. If it's a function it can't be false.
Yeah I just wasn't sure if v was actually functions like I thought or if it could ever possibly be something else.

Originally Posted by Sasky View Post
As far as the short circuit, it could be simplified even more if v(slot) always returns a boolean:
Lua Code:
  1. function(slot)
  2.     for _,v in pairs(filters[filterType]) do
  3.         if not v(slot) then
  4.             return false
  5.         end
  6.     end
  7.     return true
  8. end
If you hit false, it'll carry the false throughout, and the rest of the filters aren't necessary (as merlight noted) so you can immediately exit. Similarly, this also means a true return will only happen if and only if it iterates through the whole loop. And every time it processes the whole loop it'll return true, so the running assignment is unnecessary. Not as much of an optimization as early exit, but does save some assignment operations.
Oh, nice one.
  Reply With Quote