Browse files

Merge pull request #807 from samdark/performance_optimizations

replaced array_push with faster alternative
  • Loading branch information...
2 parents 17bfff0 + 363f7b5 commit fbad5a3ab33c0af1d4b55ff7d7196af1fb68ae03 @samdark samdark committed Jun 14, 2012
Showing with 9 additions and 11 deletions.
  1. +1 −1 framework/collections/CQueue.php
  2. +1 −1 framework/collections/CStack.php
  3. +7 −9 framework/web/helpers/CJSON.php
View
2 framework/collections/CQueue.php
@@ -138,7 +138,7 @@ public function dequeue()
public function enqueue($item)
{
++$this->_c;
- array_push($this->_d,$item);
+ $this->_d[]=$item;
}
/**
View
2 framework/collections/CStack.php
@@ -139,7 +139,7 @@ public function pop()
public function push($item)
{
++$this->_c;
- array_push($this->_d,$item);
+ $this->_d[]=$item;
}
/**
View
16 framework/web/helpers/CJSON.php
@@ -470,9 +470,7 @@ public static function decode($str, $useArray=true)
}
}
- array_push($stk, array('what' => self::JSON_SLICE,
- 'where' => 0,
- 'delim' => false));
+ $stk[] = array('what' => self::JSON_SLICE, 'where' => 0, 'delim' => false);
$chrs = substr($str, 1, -1);
$chrs = self::reduceString($chrs);
@@ -500,12 +498,12 @@ public static function decode($str, $useArray=true)
// found a comma that is not inside a string, array, etc.,
// OR we've reached the end of the character list
$slice = substr($chrs, $top['where'], ($c - $top['where']));
- array_push($stk, array('what' => self::JSON_SLICE, 'where' => ($c + 1), 'delim' => false));
+ $stk[] = array('what' => self::JSON_SLICE, 'where' => ($c + 1), 'delim' => false);
//print("Found split at {$c}: ".substr($chrs, $top['where'], (1 + $c - $top['where']))."\n");
if (reset($stk) == self::JSON_IN_ARR) {
// we are in an array, so just push an element onto the stack
- array_push($arr, self::decode($slice,$useArray));
+ $arr[] = self::decode($slice,$useArray);
} elseif (reset($stk) == self::JSON_IN_OBJ) {
// we are in an object, so figure
@@ -538,7 +536,7 @@ public static function decode($str, $useArray=true)
} elseif ((($chrs{$c} == '"') || ($chrs{$c} == "'")) && ($top['what'] != self::JSON_IN_STR)) {
// found a quote, and we are not inside a string
- array_push($stk, array('what' => self::JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c}));
+ $stk[] = array('what' => self::JSON_IN_STR, 'where' => $c, 'delim' => $chrs{$c});
//print("Found start of string at {$c}\n");
} elseif (($chrs{$c} == $top['delim']) &&
@@ -552,7 +550,7 @@ public static function decode($str, $useArray=true)
} elseif (($chrs{$c} == '[') &&
in_array($top['what'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
// found a left-bracket, and we are in an array, object, or slice
- array_push($stk, array('what' => self::JSON_IN_ARR, 'where' => $c, 'delim' => false));
+ $stk[] = array('what' => self::JSON_IN_ARR, 'where' => $c, 'delim' => false);
//print("Found start of array at {$c}\n");
} elseif (($chrs{$c} == ']') && ($top['what'] == self::JSON_IN_ARR)) {
@@ -563,7 +561,7 @@ public static function decode($str, $useArray=true)
} elseif (($chrs{$c} == '{') &&
in_array($top['what'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
// found a left-brace, and we are in an array, object, or slice
- array_push($stk, array('what' => self::JSON_IN_OBJ, 'where' => $c, 'delim' => false));
+ $stk[] = array('what' => self::JSON_IN_OBJ, 'where' => $c, 'delim' => false);
//print("Found start of object at {$c}\n");
} elseif (($chrs{$c} == '}') && ($top['what'] == self::JSON_IN_OBJ)) {
@@ -574,7 +572,7 @@ public static function decode($str, $useArray=true)
} elseif (($substr_chrs_c_2 == '/*') &&
in_array($top['what'], array(self::JSON_SLICE, self::JSON_IN_ARR, self::JSON_IN_OBJ))) {
// found a comment start, and we are in an array, object, or slice
- array_push($stk, array('what' => self::JSON_IN_CMT, 'where' => $c, 'delim' => false));
+ $stk[] = array('what' => self::JSON_IN_CMT, 'where' => $c, 'delim' => false);
$c++;
//print("Found start of comment at {$c}\n");

0 comments on commit fbad5a3

Please sign in to comment.