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 #1

Updated by Claus Due about 6 years ago

Marked as bug since technically, throwing a 100mb string after this function causes all 100mb to be scanned even if the needle is a single byte (that's not contained in the haystack).

Actions #2

Updated by Gerrit Code Review about 6 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58533

Actions #3

Updated by Gerrit Code Review about 6 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58533

Actions #4

Updated by Gerrit Code Review about 6 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58533

Actions #5

Updated by Gerrit Code Review about 6 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58533

Actions #6

Updated by Gerrit Code Review about 6 years ago

Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58533

Actions #7

Updated by Gerrit Code Review about 6 years ago

Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58533

Actions #8

Updated by Gerrit Code Review almost 6 years ago

Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/58533

Actions #9

Updated by Christian Eßl about 5 years ago

  • Category set to Performance
Actions #10

Updated by Gerrit Code Review almost 5 years ago

Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #11

Updated by Gerrit Code Review almost 5 years ago

Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #12

Updated by Gerrit Code Review almost 5 years ago

Patch set 10 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #13

Updated by Gerrit Code Review almost 5 years ago

Patch set 11 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #14

Updated by Gerrit Code Review almost 5 years ago

Patch set 12 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #15

Updated by Gerrit Code Review almost 5 years ago

Patch set 13 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #16

Updated by Gerrit Code Review almost 5 years ago

Patch set 14 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #17

Updated by Gerrit Code Review almost 5 years ago

Patch set 15 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at https://review.typo3.org/c/Packages/TYPO3.CMS/+/58533

Actions #18

Updated by Susanne Moog almost 5 years ago

  • Status changed from Under Review to Closed

see comments in review.

Actions

Also available in: Atom PDF