Skip to content

Commit

Permalink
Optimize Packager::req a bit so only once a Packager_Builder instance…
Browse files Browse the repository at this point in the history
… is created
  • Loading branch information
Arian committed Aug 14, 2011
1 parent c99bf9b commit 604a559
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
6 changes: 4 additions & 2 deletions Packager.php
Expand Up @@ -57,11 +57,13 @@ public function addAlias($alias, $url){
* @return Packager_Builder
*/
public function req(array $ids){
foreach ($ids as $id) if (!in_array($id, $this->_skip)) $this->_req($id);
foreach ($ids as $id) $this->_req($id);
return new Packager_Builder($this->_modules);
}

protected function _req($id){
if (in_array($id, $this->_skip)) return;

$filename = $id;
$extension = Path::extname($filename);
$amd = !in_array($extension, array('.js', '.css'/* more? */));
Expand Down Expand Up @@ -152,7 +154,7 @@ protected function _req($id){

$this->_files[$filename] = $id;

if (count($deps)) $this->req($deps);
foreach ($deps as $_dep) $this->_req($_dep);
}

protected function _analyze($code){
Expand Down
3 changes: 3 additions & 0 deletions YAMLExporter.php
@@ -1,5 +1,8 @@
<?php

include_once dirname(__FILE__) . '/Path.php';
include_once dirname(__FILE__) . '/Builder.php';

class Packager_YAMLExporter {

protected $_modules;
Expand Down
6 changes: 3 additions & 3 deletions test/php/BuilderTest.php
Expand Up @@ -144,10 +144,10 @@ public function testOutputByPackage(){
'PackageA' => "\n"
. "define('PackageA/a', ['./b', 'PackageA/c', 'PackageB/b'], function(b1, b2){\n"
. " return 'a';\n"
. "});\n/*----*/\n"
. "});\n//----\n"
. "define('PackageA/b', function(){\n"
. " return 'b';\n"
. "});\n/*----*/\n"
. "});\n//----\n"
. "define('PackageA/c', function(){\n"
. " return 'c';\n"
. "});\n",
Expand All @@ -156,7 +156,7 @@ public function testOutputByPackage(){
. " return 'b';\n"
. "});\n");

$this->assertEquals($expected, $builder->outputByPackage('/*----*/'));
$this->assertEquals($expected, $builder->outputByPackage('//----'));

}

Expand Down

0 comments on commit 604a559

Please sign in to comment.