-- Mathieu Suen <[email protected]> wrote
(on Tuesday, 21 July 2009, 10:26 AM +0200):
> Mathieu Suen a écrit :
> > Hi,
> >
> > I am doing dome benchmark and I see the method  
> > Zend_Form_Element::getAttribs is taking a lot of time. By looking of 
> > the code it seems that the get_object_vars consum a lot of time.
> >
> > And since there is 25 inst var that are protected/private it don't  
> > return a lot of attribs.
> >
> > By looking of all the subclasses I can see that most of the time there  
> > is the helper that are redefine  and a few attribut add.
> >
> > So I propose to change the setAttrib so that we cache all the attribs  
> > name and we can then retrive the attrib without using get_object_vars  
> > and doing the big foreach loop.
> >
> > What do you think?

Makes sense. Can you post an issue to the tracker with this patch,
please?

> See attach file to see what it can look like.
>
> -- 
> -- Mathieu Suen
> --

> --- global/library/Zend/Form/.svn/text-base/Element.php.svn-base      
> 2009-07-06 08:38:16.000000000 +0200
> +++ global/library/Zend/Form/Element.php      2009-07-21 09:34:16.000000000 
> +0200
> @@ -195,6 +195,11 @@ class Zend_Form_Element implements Zend_
>       */
>      protected $_view;
>  
> +     /**
> +      * @var array
> +      */
> +     protected $_attribsName = array();
> +
>      /**
>       * Constructor
>       *
> @@ -227,6 +232,12 @@ class Zend_Form_Element implements Zend_
>              throw new Zend_Form_Exception('Zend_Form_Element requires each 
> element to have a name');
>          }
>  
> +             $this->_attribsName[] = 'helper';
> +             $this->_attribsName[] = 'multiple';
> +             $this->_attribsName[] = 'options';
> +             $this->_attribsName[] = 'src';
> +             $this->_attribsName[] = 'checked';
> +             $this->_attribsName[] = 'class';
>          /**
>           * Extensions
>           */
> @@ -793,6 +804,7 @@ class Zend_Form_Element implements Zend_
>              unset($this->$name);
>          } else {
>              $this->$name = $value;
> +                     $this->_attribsName[] = $name;
>          }
>  
>          return $this;
> @@ -836,10 +848,10 @@ class Zend_Form_Element implements Zend_
>       */
>      public function getAttribs()
>      {
> -        $attribs = get_object_vars($this);
> -        foreach ($attribs as $key => $value) {
> -            if ('_' == substr($key, 0, 1)) {
> -                unset($attribs[$key]);
> +             $attribs = array();
> +        foreach ($this->_attribsName as $name) {
> +            if (isset($this->$name)) {
> +                $attribs[$name] = $this->$name;
>              }
>          }
>  


-- 
Matthew Weier O'Phinney
Project Lead            | [email protected]
Zend Framework          | http://framework.zend.com/

Reply via email to