Performance/reliability improvement for leaving unrecognised tags.

error_behaviour = self::LEAVE is the default behaviour. In this case,
we don’t even need to bother recognising such tags. Rather than
replacing with marker images and re-inserting the original text after
we’re done, we can leave them alone.

This should make the code faster and more reliable.
This commit is contained in:
Sam Minnee 2015-06-22 11:31:12 +01:00
parent 6d05c57881
commit d7241958ff

View File

@ -320,7 +320,18 @@ class ShortcodeParser extends Object {
}
}
}
// Step 3: remove any tags that don't have handlers registered
// Only do this if self::$error_behavior == self::LEAVE
// This is optional but speeds things up.
if(self::$error_behavior == self::LEAVE) {
foreach($tags as $i => $tag) {
if(empty($this->shortcodes[$tag['open']])) {
unset($tags[$i]);
}
}
}
return array_values($tags);
}
@ -550,7 +561,7 @@ class ShortcodeParser extends Object {
// Find the parents. Do this before DOM modification, since SPLIT might cause parents to move otherwise
$parents = $this->findParentsForMarkers($shortcodes);
foreach($shortcodes as $shortcode) {
$tag = $tags[$shortcode->getAttribute('data-tagid')];
$parent = $parents[$shortcode->getAttribute('data-parentid')];