Skip to content

Commit

Permalink
Remove numerous calls to in_array().
Browse files Browse the repository at this point in the history
Replacing in_array() with isset() saves a number of calls which add up
over time.
  • Loading branch information
markstory committed Aug 7, 2014
1 parent 283bcd0 commit 2789ab0
Showing 1 changed file with 21 additions and 4 deletions.
25 changes: 21 additions & 4 deletions src/View/StringTemplate.php
Expand Up @@ -36,9 +36,26 @@ class StringTemplate {
* @var array
*/
protected $_compactAttributes = array(
'compact', 'checked', 'declare', 'readonly', 'disabled', 'selected',
'defer', 'ismap', 'nohref', 'noshade', 'nowrap', 'multiple', 'noresize',
'autoplay', 'controls', 'loop', 'muted', 'required', 'novalidate', 'formnovalidate'
'compact' => true,
'checked' => true,
'declare' => true,
'readonly' => true,
'disabled' => true,
'selected' => true,
'defer' => true,
'ismap' => true,
'nohref' => true,
'noshade' => true,
'nowrap' => true,
'multiple' => true,
'noresize' => true,
'autoplay' => true,
'controls' => true,
'loop' => true,
'muted' => true,
'required' => true,
'novalidate' => true,
'formnovalidate' => true,
);

/**
Expand Down Expand Up @@ -253,7 +270,7 @@ protected function _formatAttribute($key, $value, $escape = true) {
return "$value=\"$value\"";
}
$truthy = [1, '1', true, 'true', $key];
$isMinimized = in_array($key, $this->_compactAttributes);
$isMinimized = isset($this->_compactAttributes[$key]);
if ($isMinimized && in_array($value, $truthy, true)) {
return "$key=\"$key\"";
}
Expand Down

0 comments on commit 2789ab0

Please sign in to comment.