[TYPO3-core] RFC: feature #2743
Wolfgang Klinger
wolfgang at stufenlos.net
Thu Mar 2 15:11:30 CET 2006
*hiya!*
Type: patch / feature
Speed up substituteConstants with preg_replace_callback
BT reference: http://bugs.typo3.org/view.php?id=2743
preg_replace_callback is available with PHP >= 4.0.5
I tested it myself, it's definitely faster.
There's a similar method in tsparser_ext, but the tests there
showed that the current way is faster, so I didn't not change that
method.
Please test.
bye
Wolfgang
-------------- next part --------------
--- TYPO3core/t3lib/class.t3lib_tstemplate.php 2006-02-27 20:45:20.000000000 +0100
+++ TYPO3core_testing/t3lib/class.t3lib_tstemplate.php 2006-03-02 14:38:19.000000000 +0100
@@ -965,15 +965,20 @@
*/
function substituteConstants($all) {
if ($this->tt_track) $GLOBALS['TT']->setTSlogMessage('Constants to substitute: '.count($this->flatSetup));
- reset($this->flatSetup);
- while (list($const,$val)=each($this->flatSetup)) {
- if (!is_array($val)) {
- $all = str_replace('{$'.$const.'}',$val,$all);
- }
- }
- return $all;
+
+ return preg_replace_callback('/\{\$(.[^}]+)\}/', array($this, 'substituteConstantsCallBack'), $all);
}
+ /**
+ * Call back method for preg_replace_callback in substituteConstants
+ *
+ * @param array Regular expression matches
+ * @return string Replacement
+ * @see substituteConstants()
+ */
+ function substituteConstantsCallBack($matches) {
+ return isset($this->flatSetup[$matches[1]]) ? $this->flatSetup[$matches[1]] : $matches[0];
+ }
@@ -1543,4 +1548,4 @@
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']) {
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['t3lib/class.t3lib_tstemplate.php']);
}
-?>
\ No newline at end of file
+?>
More information about the TYPO3-team-core
mailing list