Fix performance regressions in addon loading
Regression caused by !2501 (merged). In order to fix a bug in sprite patches not loading properly when there are empty folders present, the code added a function to check if a directory was empty. That function worked by iterating the contents, and if it had any entries, it would iterate it again to get the actual start and end.
The problem with this approach is that the iteration procedures uses case-insensitive string comparison for iteration, which is a slow process, and doing it twice caused performance to suffer pretty badly. This simply refactors it to re-use the results of the empty check if it's non-empty, causing it to always iterate only once.