More efficient return from _findSection.

This commit is contained in:
Justin Hileman
2011-06-13 01:23:19 -04:00
parent 9af6b2033e
commit f95f8c09a8
+11 -8
View File
@@ -212,9 +212,7 @@ class Mustache {
*/ */
protected function _renderTemplate($template) { protected function _renderTemplate($template) {
if ($section = $this->_findSection($template)) { if ($section = $this->_findSection($template)) {
list($section, $offset, $type, $tag_name, $content) = $section; list($before, $type, $tag_name, $content, $after) = $section;
$before = substr($template, 0, $offset);
$after = substr($template, $offset + strlen($section));
$replace = ''; $replace = '';
$val = $this->_getVariable($tag_name); $val = $this->_getVariable($tag_name);
@@ -276,7 +274,7 @@ class Mustache {
* *
* @access protected * @access protected
* @param string $template * @param string $template
* @return array $section, $offset, $type, $tag_name and $content * @return array $before, $type, $tag_name, $content and $after
*/ */
protected function _findSection($template) { protected function _findSection($template) {
$regEx = $this->_prepareSectionRegEx($this->_otag, $this->_ctag); $regEx = $this->_prepareSectionRegEx($this->_otag, $this->_ctag);
@@ -316,10 +314,14 @@ class Mustache {
} }
if (empty($section_stack)) { if (empty($section_stack)) {
$section = substr($template, $section_start, $search_offset - $section_start); // $before, $type, $tag_name, $content, $after
$content = substr($template, $content_start, $offset - $content_start); return array(
substr($template, 0, $section_start),
return array($section, $section_start, $section_type, $tag_name, $content); $section_type,
$tag_name,
substr($template, $content_start, $offset - $content_start),
substr($template, $search_offset),
);
} }
break; break;
} }
@@ -847,3 +849,4 @@ class MustacheException extends Exception {
const UNKNOWN_PRAGMA = 4; const UNKNOWN_PRAGMA = 4;
} }