+
Skip to content

reduce memory usage on large templates by reducing token size #373

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ public static function verify(&$context, $template)
Parser::setDelimiter($context);

while (preg_match($context['tokens']['search'], $template, $matches)) {
$nextTemplate = "{$matches[Token::POS_RSPACE]}{$matches[Token::POS_ROTHER]}";

// Skip a token when it is slash escaped
if ($context['flags']['slash'] && ($matches[Token::POS_LSPACE] === '') && preg_match('/^(.*?)(\\\\+)$/s', $matches[Token::POS_LOTHER], $escmatch)) {
if (strlen($escmatch[2]) % 4) {
Expand All @@ -57,7 +59,7 @@ public static function verify(&$context, $template)
}
static::pushToken($context, $V);
}
$template = "{$matches[Token::POS_RSPACE]}{$matches[Token::POS_ROTHER]}";
$template = $nextTemplate;
}
static::pushToken($context, $template);

Expand Down Expand Up @@ -630,6 +632,10 @@ protected static function token(&$token, &$context)
// Handle spacing (standalone tags, partial indent)
static::spacing($token, $context, (($token[Token::POS_OP] === '') || ($token[Token::POS_OP] === '&')) && (!$context['flags']['else'] || !isset($vars[0][0]) || ($vars[0][0] !== 'else')) || ($context['flags']['nostd'] > 0));

// reduce token memory usage by resetting some keys
$token[0] = '';
$token[Token::POS_ROTHER] = '';

$inlinepartial = static::inlinePartial($context, $vars);
$partialblock = static::partialBlock($context, $vars);

Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载