Skip to content

Instantly share code, notes, and snippets.

@dimkalinux
Last active December 22, 2015 00:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dimkalinux/86762bc459597e6f518e to your computer and use it in GitHub Desktop.
Save dimkalinux/86762bc459597e6f518e to your computer and use it in GitHub Desktop.
Lower memory usage on Latte template with big variables
diff -ur nette/Nette/Latte/Macros/UIMacros.php nette.patched/Nette/Latte/Macros/UIMacros.php
--- nette/Nette/Latte/Macros/UIMacros.php 2013-08-08 02:14:19.000000000 +0300
+++ nette.patched/Nette/Latte/Macros/UIMacros.php 2013-08-30 19:13:24.000000000 +0300
@@ -98,7 +98,7 @@
$prolog[] = "//\n// block $name\n//\n"
. "if (!function_exists(\$_l->blocks[" . var_export($name, TRUE) . "][] = '$func')) { "
. "function $func(\$_l, \$_args) { "
- . (PHP_VERSION_ID > 50208 ? 'extract($_args)' : 'foreach ($_args as $__k => $__v) $$__k = $__v') // PHP bug #46873
+ . 'foreach ($_args as $__k => $__v) $$__k = $__v' // PHP bug #46873
. ($snippet ? '; $_control->validateControl(' . var_export(substr($name, 1), TRUE) . ')' : '')
. "\n?>$code<?php\n}}";
}
@@ -250,7 +250,7 @@
return "\n\n//\n// block $name\n//\n"
. "if (!function_exists(\$_l->blocks[$fname]['{$this->getCompiler()->getTemplateId()}'] = '$func')) { "
. "function $func(\$_l, \$_args) { "
- . (PHP_VERSION_ID > 50208 ? 'extract($_args)' : 'foreach ($_args as $__k => $__v) $$__k = $__v'); // PHP bug #46873
+ . 'foreach ($_args as $__k => $__v) $$__k = $__v'; // PHP bug #46873
}
}
diff -ur nette/Nette/Utils/LimitedScope.php nette.patched/Nette/Utils/LimitedScope.php
--- nette/Nette/Utils/LimitedScope.php 2013-08-08 02:14:19.000000000 +0300
+++ nette.patched/Nette/Utils/LimitedScope.php 2013-08-30 19:21:16.000000000 +0300
@@ -65,7 +65,7 @@
if (self::$vars === TRUE) {
return require func_get_arg(0);
}
- extract(self::$vars);
+ foreach (self::$vars as $k => $v) { $$k = $v; }
}
return require func_get_arg(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment