Optimizations for checkcase.rb: add caching for path lookups so
we don't end up looking up the same directory more than once. Also
include negative lookups - those where no matching path was
found in the cache. This brings the overhead of check new, large
branches down to a few commands.