From 604a559cf31a0d3f071a18ad6b1c4a1b2524894b Mon Sep 17 00:00:00 2001 From: Arian Date: Sun, 14 Aug 2011 12:33:57 +0200 Subject: [PATCH] Optimize Packager::req a bit so only once a Packager_Builder instance is created --- Packager.php | 6 ++++-- YAMLExporter.php | 3 +++ test/php/BuilderTest.php | 6 +++--- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Packager.php b/Packager.php index 9cedbad..174be90 100755 --- a/Packager.php +++ b/Packager.php @@ -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? */)); @@ -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){ diff --git a/YAMLExporter.php b/YAMLExporter.php index 7392da2..63f521b 100644 --- a/YAMLExporter.php +++ b/YAMLExporter.php @@ -1,5 +1,8 @@ "\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", @@ -156,7 +156,7 @@ public function testOutputByPackage(){ . " return 'b';\n" . "});\n"); - $this->assertEquals($expected, $builder->outputByPackage('/*----*/')); + $this->assertEquals($expected, $builder->outputByPackage('//----')); }