-- Kendall Bennett <[email protected]> wrote (on Saturday, 02 May 2009, 03:56 PM -0700): > Wow. That did not come out formatted correct. Let me re-send this one > formatted correctly: > > I have been stepping through all the Zend Framework code to see how it all > fits together, and thinking about how it all will affect the performance of > applications that are written with it, when I came across something that > looks odd to me in the the Zend_View_Abstract::_getPlugin() implementation. > Specifically the function is as follows: > > private function _getPlugin($type, $name) > { > $name = ucfirst($name); > switch ($type) { > case 'filter': > $storeVar = '_filterClass'; > $store = $this->_filterClass; > break; > case 'helper': > $storeVar = '_helper'; > $store = $this->_helper; > break; > } > > if (!isset($store[$name])) { > $class = $this->getPluginLoader($type)->load($name); > $store[$name] = new $class(); > if (method_exists($store[$name], 'setView')) { > $store[$name]->setView($this); > } > } > > $this->$storeVar = $store; > return $store[$name]; > } > > The thing that has me wondering is the second last line. This line > re-assigns the $store value into the $this->_helper or $this->_filterClass > variables. But in the case where the plugin has already been loaded and > already exists in $store, this is just re-assigning the same value. I don¹t > know how PHP optimizes things, but I would expect this would cause the > entire array to be re-assigned, and the original contents of the array to go > onto the garbage collection heap. Since the contents have not changes, > shouldn¹t this be written this way? > > if (!isset($store[$name])) { > $class = $this->getPluginLoader($type)->load($name); > $store[$name] = new $class(); > if (method_exists($store[$name], 'setView')) { > $store[$name]->setView($this); > } > $this->$storeVar = $store; // Only update the store if it > // actually changed? > } > > return $store[$name];
Yep -- please file an issue in the tracker for this improvement. -- Matthew Weier O'Phinney Project Lead | [email protected] Zend Framework | http://framework.zend.com/
