Task #54091
closedEpic #55070: Workpackages
Epic #55065: WP: Overall System Performance (Backend and Frontend)
Story #55078: Optimize PHP code performance in TYPO3 methods
Use === operator instead of strlen() to check for zero length strings
100%
Description
Use the === operator instead of the strlen() function to check for strings of length zero.
This can give a performance improvement of factor 3.
Short note: Although some source claim that strlen() has O(1), for some reason the comparison against an empty string is still faster.
Nevertheless, besides the possible performance improvement, this change also improves readability.
Updated by Stefan Neufeind about 11 years ago
In general I like the idea.
Beware though that strlen() also returns 0 for FALSE, will cast non-strings to a string first (thus correctly gives string-length of integers etc.) and such.
Updated by Jo Hasenau about 11 years ago
Beware though that strlen() also returns 0 for FALSE, will cast non-strings to a string first (thus correctly gives string-length of integers etc.) and such.
So
(string)$foo === ''
should do the job and strlen() can stay for those cases that expect a length > 0
Updated by Ernesto Baschny almost 11 years ago
- Target version set to 6.2.0
- Parent task changed from #52949 to #55078
Updated by Markus Klein almost 11 years ago
I tested strlen() a bit.
$c = FALSE;
echo strlen($c); // 0
echo (string)$c === '' ? 'empty' : 'not empty'; // empty
echo $c === '' ? 'empty' : 'not empty'; // not empty
$c = TRUE;
echo strlen($c); // 1
echo (string)$c === '' ? 'empty' : 'not empty'; // not empty
echo $c === '' ? 'empty' : 'not empty'; // not empty
So it suffices to do the cast in cases were we are not sure about the type.
Updated by Gerrit Code Review almost 11 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/27091
Updated by Gerrit Code Review almost 11 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/27091
Updated by Gerrit Code Review almost 11 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/27091
Updated by Gerrit Code Review almost 11 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/27091
Updated by Gerrit Code Review almost 11 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/27091
Updated by Gerrit Code Review almost 11 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/27091
Updated by Stefan Neufeind almost 11 years ago
- Subject changed from Use === operator instead of strlen() to check for zero length stirngs to Use === operator instead of strlen() to check for zero length strings
Updated by Gerrit Code Review almost 11 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/27091
Updated by Gerrit Code Review almost 11 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/27091
Updated by Gerrit Code Review almost 11 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/27091
Updated by Markus Klein almost 11 years ago
- Status changed from Under Review to Resolved
- % Done changed from 0 to 100
Applied in changeset de27a20afbd8f413f60029afc5622c7b33212322.
Updated by Gerrit Code Review almost 11 years ago
- Status changed from Resolved 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/27794
Updated by Gerrit Code Review almost 11 years ago
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/28017
Updated by Michiel Roos almost 11 years ago
To make travis pass all the failing tests:
One issue is in \TYPO3\CMS\Core\Utility\GeneralUtility::xml2arrayProcess()
Around line: 2273:
if ((string)$val['attributes']['index'] !== '') {
$tagName = $val['attributes']['index'];
}
Two more string casts are needed in: typo3/sysext/extbase/Classes/Scheduler/FieldProvider.php around line 244
Two more string casts are needed in typo3/sysext/extensionmanager/Classes/Utility/EmConfUtility.php around line 95:
- if (strlen($emConf['PHP_version'])) {
+ if ((string)$emConf['PHP_version'] !== '') {
$emConf['constraints']['depends']['php'] = $emConf['PHP_version'];
}
- if (strlen($emConf['TYPO3_version'])) {
+ if ((string)$emConf['TYPO3_version'] !== '') {
$emConf['constraints']['depends']['typo3'] = $emConf['TYPO3_version'];
}
Updated by Gerrit Code Review almost 11 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/27794
Updated by Gerrit Code Review almost 11 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/27794
Updated by Gerrit Code Review over 10 years ago
Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/27794
Updated by Gerrit Code Review about 10 years ago
Patch set 5 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/27794
Updated by Gerrit Code Review about 10 years ago
Patch set 6 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/27794
Updated by Gerrit Code Review about 10 years ago
Patch set 7 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/27794
Updated by Gerrit Code Review about 10 years ago
Patch set 8 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/27794
Updated by Gerrit Code Review about 10 years ago
Patch set 9 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/27794
Updated by Markus Klein about 10 years ago
- Status changed from Under Review to Resolved
Applied in changeset 4722b6cf5c97ab415d3d35687ed77750b97e3258.
Updated by Mathias Brodala almost 7 years ago
- Related to Bug #84434: TypoScript ifBlank does not work with strlen like expected added