[TASK] Avoid unused xpath when parsing locallang.xml 51/51851/4
authorStephan Großberndt <stephan@grossberndt.de>
Sat, 25 Feb 2017 11:30:09 +0000 (12:30 +0100)
committerWouter Wolters <typo3@wouterwolters.nl>
Wed, 5 Apr 2017 18:11:11 +0000 (20:11 +0200)
Increased performance by avoiding an xpath query if the requested
element is not 'target'.

Releases: master, 7.6
Resolves: #80016
Change-Id: I509de5bfb79701efe966d16bc29aaae6a46050ef
Reviewed-on: https://review.typo3.org/51851
Reviewed-by: Faton Haliti <fha@systime.dk>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Xavier Perseguers <xavier@typo3.org>
Tested-by: Xavier Perseguers <xavier@typo3.org>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/core/Classes/Localization/Parser/LocallangXmlParser.php

index ff3a678..3cf0508 100644 (file)
@@ -74,20 +74,22 @@ class LocallangXmlParser extends AbstractXmlParser
             throw new InvalidXmlFileException('Invalid locallang.xml language file "' . PathUtility::stripPathSitePrefix($this->sourcePath) . '"', 1487944884);
         }
 
-        // Check if the source llxml file contains localized records
-        $localizedBodyOfFileTag = $root->data->xpath('languageKey[@index=\'' . $this->languageKey . '\']');
         if ($element === 'source' || $this->languageKey === 'default') {
             $parsedData = $this->getParsedDataForElement($bodyOfFileTag, $element);
         } else {
             $parsedData = [];
         }
-        if ($element === 'target' && isset($localizedBodyOfFileTag[0]) && $localizedBodyOfFileTag[0] instanceof \SimpleXMLElement) {
-            $parsedDataTarget = $this->getParsedDataForElement($localizedBodyOfFileTag[0], $element);
-            $mergedData = $parsedDataTarget + $parsedData;
-            if ($this->languageKey === 'default') {
-                $parsedData = array_intersect_key($mergedData, $parsedData, $parsedDataTarget);
-            } else {
-                $parsedData = array_intersect_key($mergedData, $parsedDataTarget);
+        if ($element === 'target') {
+            // Check if the source llxml file contains localized records
+            $localizedBodyOfFileTag = $root->data->xpath('languageKey[@index=\'' . $this->languageKey . '\']');
+            if (isset($localizedBodyOfFileTag[0]) && $localizedBodyOfFileTag[0] instanceof \SimpleXMLElement) {
+                $parsedDataTarget = $this->getParsedDataForElement($localizedBodyOfFileTag[0], $element);
+                $mergedData = $parsedDataTarget + $parsedData;
+                if ($this->languageKey === 'default') {
+                    $parsedData = array_intersect_key($mergedData, $parsedData, $parsedDataTarget);
+                } else {
+                    $parsedData = array_intersect_key($mergedData, $parsedDataTarget);
+                }
             }
         }
         return $parsedData;