Fix n² complexity in cfkey

The optimizer has a helper that checks statements for equality, cfkey.  It is currently n², and could be made linear by memoization.
incidentally i liked your version of this better

```lua
local result = cache[arg]
if result == nil then
  result = f(arg)
  cache[arg] = result
end
return result
```