Project

General

Profile

Actions

Task #54095

closed

Optimization of GeneralUtility::getFilesInDir()

Added by Michiel Roos over 10 years ago. Updated over 5 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Performance
Target version:
Start date:
2014-02-08
Due date:
2014-02-08
% Done:

100%

Estimated time:
TYPO3 Version:
6.1
PHP Version:
5.3
Tags:
Complexity:
easy
Sprint Focus:

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.


Related issues 2 (0 open2 closed)

Related to TYPO3 Core - Task #56121: getFilesInDirCanOrderByMtime-test should use vfsClosedStefan Neufeind2014-02-19

Actions
Follows TYPO3 Core - Task #55762: getFilesInDir() needs unit testsClosed2014-02-07

Actions
Actions

Also available in: Atom PDF