From 0d383257ba1a510da01b99f6408193b925d0fbaa Mon Sep 17 00:00:00 2001
From: Michiel Roos <michiel@maxserv.nl>
Date: Tue, 28 Jan 2014 10:04:52 +0100
Subject: [PATCH] [TASK] Optimize GeneralUtility::trimExplode()

This often used method can be about 5% more performant by rewriting it.

Change-Id: Iee80a35ebd98c3521a75977bc7ab45d170858e24
Resolves: #55198
Releases: 6.2
Reviewed-on: https://review.typo3.org/27086
Reviewed-by: Markus Klein
Tested-by: Markus Klein
---
 .../core/Classes/Utility/GeneralUtility.php   | 64 +++++++++----------
 1 file changed, 31 insertions(+), 33 deletions(-)

diff --git a/typo3/sysext/core/Classes/Utility/GeneralUtility.php b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
index 3ec82b51441d..f49da5850682 100644
--- a/typo3/sysext/core/Classes/Utility/GeneralUtility.php
+++ b/typo3/sysext/core/Classes/Utility/GeneralUtility.php
@@ -1510,8 +1510,7 @@ class GeneralUtility {
 	 * @return array Exploded values
 	 */
 	static public function trimExplode($delim, $string, $removeEmptyValues = FALSE, $limit = 0) {
-		$explodedValues = explode($delim, $string);
-		$result = array_map('trim', $explodedValues);
+		$result = array_map('trim', explode($delim, $string));
 		if ($removeEmptyValues) {
 			$temp = array();
 			foreach ($result as $value) {
@@ -1521,14 +1520,12 @@ class GeneralUtility {
 			}
 			$result = $temp;
 		}
-		if ($limit !== 0) {
-			if ($limit < 0) {
-				$result = array_slice($result, 0, $limit);
-			} elseif (count($result) > $limit) {
-				$lastElements = array_slice($result, $limit - 1);
-				$result = array_slice($result, 0, $limit - 1);
-				$result[] = implode($delim, $lastElements);
-			}
+		if ($limit > 0 && count($result) > $limit) {
+			$lastElements = array_slice($result, $limit - 1);
+			$result = array_slice($result, 0, $limit - 1);
+			$result[] = implode($delim, $lastElements);
+		} elseif ($limit < 0) {
+			$result = array_slice($result, 0, $limit);
 		}
 		return $result;
 	}
@@ -3465,29 +3462,30 @@ Connection: close
 			case '_ARRAY':
 				$out = array();
 				// Here, list ALL possible keys to this function for debug display.
-				$envTestVars = self::trimExplode(',', '
-						HTTP_HOST,
-						TYPO3_HOST_ONLY,
-						TYPO3_PORT,
-						PATH_INFO,
-						QUERY_STRING,
-						REQUEST_URI,
-						HTTP_REFERER,
-						TYPO3_REQUEST_HOST,
-						TYPO3_REQUEST_URL,
-						TYPO3_REQUEST_SCRIPT,
-						TYPO3_REQUEST_DIR,
-						TYPO3_SITE_URL,
-						TYPO3_SITE_SCRIPT,
-						TYPO3_SSL,
-						TYPO3_REV_PROXY,
-						SCRIPT_NAME,
-						TYPO3_DOCUMENT_ROOT,
-						SCRIPT_FILENAME,
-						REMOTE_ADDR,
-						REMOTE_HOST,
-						HTTP_USER_AGENT,
-						HTTP_ACCEPT_LANGUAGE', TRUE);
+				$envTestVars = array(
+					'HTTP_HOST',
+					'TYPO3_HOST_ONLY',
+					'TYPO3_PORT',
+					'PATH_INFO',
+					'QUERY_STRING',
+					'REQUEST_URI',
+					'HTTP_REFERER',
+					'TYPO3_REQUEST_HOST',
+					'TYPO3_REQUEST_URL',
+					'TYPO3_REQUEST_SCRIPT',
+					'TYPO3_REQUEST_DIR',
+					'TYPO3_SITE_URL',
+					'TYPO3_SITE_SCRIPT',
+					'TYPO3_SSL',
+					'TYPO3_REV_PROXY',
+					'SCRIPT_NAME',
+					'TYPO3_DOCUMENT_ROOT',
+					'SCRIPT_FILENAME',
+					'REMOTE_ADDR',
+					'REMOTE_HOST',
+					'HTTP_USER_AGENT',
+					'HTTP_ACCEPT_LANGUAGE'
+				);
 				foreach ($envTestVars as $v) {
 					$out[$v] = self::getIndpEnv($v);
 				}
-- 
GitLab