Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Avoid array_push() for performance reasons

According to the PHP docs, $array[] should be faster.
  • Loading branch information...
commit f07f7981b37b771d9fc0f42ad4727ad6daac7782 1 parent e1cc83a
patrikf authored
2  lib/binary.class.php
View
@@ -24,7 +24,7 @@ static public function nuint32($n, $str, $pos=0)
{
$r = array();
for ($i = 0; $i < $n; $i++, $pos += 4)
- array_push($r, Binary::uint32($str, $pos));
+ $r[] = Binary::uint32($str, $pos);
return $r;
}
2  lib/git.class.php
View
@@ -62,7 +62,7 @@ public function __construct($dir)
$dh = opendir(sprintf('%s/objects/pack', $this->dir));
while (($entry = readdir($dh)) !== FALSE)
if (preg_match('#^pack-([0-9a-fA-F]{40})\.idx$#', $entry, $m))
- array_push($this->packs, sha1_bin($m[1]));
+ $this->packs[] = sha1_bin($m[1]);
}
protected function readFanout($f, $object_name, $offset)
6 lib/git_commit.class.php
View
@@ -28,7 +28,7 @@ public function _unserialize($data)
if (!isset($meta[$parts[0]]))
$meta[$parts[0]] = array($parts[1]);
else
- array_push($meta[$parts[0]], $parts[1]);
+ $meta[$parts[0]][] = $parts[1];
}
$this->tree = sha1_bin($meta['tree'][0]);
@@ -73,7 +73,7 @@ public function getHistory()
if (!isset($inc[$parent]))
{
$inc[$parent] = 1;
- array_push($queue, $this->repo->getObject($parent));
+ $queue[] = $this->repo->getObject($parent);
}
else
$inc[$parent]++;
@@ -88,7 +88,7 @@ public function getHistory()
foreach ($commit->parents as $parent)
{
if (--$inc[$parent] == 0)
- array_push($queue, $this->repo->getObject($parent));
+ $queue[] = $this->repo->getObject($parent);
}
}
2  lib/git_tree.class.php
View
@@ -158,7 +158,7 @@ public function updateNode($path, $mode, $object)
$subtree->rehash();
$node->object = $subtree->getName();
- array_push($pending, $subtree);
+ $pending[] = $subtree;
return $pending;
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.