Issue Task Closed

#54095Optimization of GeneralUtility::getFilesInDir()

Michiel Roos 11/29/13, 18:46 updated 10/02/18, 12:09

Description

  • The current getFilesInDir calls strlen($extensionList) and strlen($excludePattern) in a while loop. These values are unchanging and should be calculated only once outside of the loop.
  • From the data provided by the pathinfo($entry) call, only the extension is used. This can be written as: pathinfo($entry, PATHINFO_EXTENSION) which returns a simple string.
  • The if condition: $prependPath ? $path . ‘/’ : ‘’ can be rewritten to use a variable variable.

But upon further inspection, it turns out that dropping the dir->read() in favor of glob() saves a lot of time.

Test results are here:

We can save even more time by dropping the is_file() check from the glob() version. We search for files matching .ext. If no ext is given this will become *.. So false positives (directories instead of files) may be found if the searched directory contains directories ending in a dot followed by one of the extensions searched for or a dot (in case . is searched). So I’ll submit a patch that does use the is_file() check.

Also, the md5 takes time . . . but is needed for backwards compatibility.

Reviews 1