Project

General

Profile

Actions

Bug #86519

closed

String "beginsWith" and "endsWith" uses strpos / strrpos which will needlessly scan the entire haystack string, wasting performance

Added by Claus Due about 6 years ago. Updated almost 5 years ago.

Status:
Closed
Priority:
Should have
Assignee:
-
Category:
Performance
Target version:
-
Start date:
2018-10-01
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
8
PHP Version:
Tags:
Complexity:
Is Regression:
Sprint Focus:

Description

There is a logical issue with the string-begins-with and -ends-with testing in StringUtility:

Logic dictates that a test for "begins with" will not need to scan a string beyond the number of characters contained in the needle. Likewise, to test for "ends with" you will not need to scan further than needle-length characters from the end of the haystack.

The use of strpos and strrpos defeats this logic by always scanning the entire string to end until any occurrence is found or none, then comparing the position at which the needle was found. A much, much more efficient choice of strategy would be to substring the haystack and use strncmp to immediately compare if the exact targeted number of bytes from start/end of haystack matches the needle.

Actions

Also available in: Atom PDF