From 562e322fe595b4d3307ff28a96c8c5fbcc284010 Mon Sep 17 00:00:00 2001 From: Fabio Bas Date: Thu, 25 Feb 2016 17:01:17 +0100 Subject: Applied some misc optimizations to class serialization MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid saving in the page state the values of class variables if they’re still the default. Reduces page state size, based on the work initiated in 8dc9d4f7d49bcbeaf4998baf74a4f4459967c1f0 --- framework/Collections/TAttributeCollection.php | 13 +++++ framework/Collections/TMap.php | 15 ++++++ framework/TComponent.php | 23 ++++---- framework/Web/UI/TControl.php | 15 ++++-- .../Web/UI/WebControls/TDataGridPagerStyle.php | 29 ++++++++++ framework/Web/UI/WebControls/TFont.php | 17 ++++++ framework/Web/UI/WebControls/TLabel.php | 2 +- framework/Web/UI/WebControls/TListItem.php | 29 ++++++++-- framework/Web/UI/WebControls/TLiteral.php | 2 +- framework/Web/UI/WebControls/TPanelStyle.php | 21 ++++++++ framework/Web/UI/WebControls/TStyle.php | 61 ++++++++++++++++++++++ framework/Web/UI/WebControls/TTextBox.php | 2 +- 12 files changed, 208 insertions(+), 21 deletions(-) (limited to 'framework') diff --git a/framework/Collections/TAttributeCollection.php b/framework/Collections/TAttributeCollection.php index a0f14efd..14a94fbd 100644 --- a/framework/Collections/TAttributeCollection.php +++ b/framework/Collections/TAttributeCollection.php @@ -44,6 +44,19 @@ class TAttributeCollection extends TMap { private $_caseSensitive=false; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_caseSensitive===false) + $exprops[] = "\0TAttributeCollection\0_caseSensitive"; + } + /** * Returns a property value or an event handler list by property or event name. * This method overrides the parent implementation by returning diff --git a/framework/Collections/TMap.php b/framework/Collections/TMap.php index d610dce6..a356fe77 100644 --- a/framework/Collections/TMap.php +++ b/framework/Collections/TMap.php @@ -41,6 +41,21 @@ class TMap extends TComponent implements IteratorAggregate,ArrayAccess,Countable */ private $_r=false; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_d===array()) + $exprops[] = "\0TMap\0_d"; + if ($this->_r===false) + $exprops[] = "\0TMap\0_r"; + } + /** * Constructor. * Initializes the list with an array or an iterable object. diff --git a/framework/TComponent.php b/framework/TComponent.php index 5901f93d..c2f00696 100644 --- a/framework/TComponent.php +++ b/framework/TComponent.php @@ -1697,16 +1697,6 @@ class TComponent return null; } - /** - * Do not call this method. This is a PHP magic method that will be called automatically - * after any unserialization; it can perform reinitialization tasks on the object. - */ - public function __wakeup() - { - if ($this->_e===null) - $this->_e = array(); - } - /** * Returns an array with the names of all variables of that object that should be serialized. * Do not call this method. This is a PHP magic method that will be called automatically @@ -1717,6 +1707,18 @@ class TComponent $a = (array)$this; $a = array_keys($a); $exprops = array(); + $this->__getZappableSleepProps($exprops); + return array_diff($a, $exprops); + } + + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { if($this->_listeningenabled===false) $exprops[] = "\0TComponent\0_listeningenabled"; if($this->_behaviorsenabled===true) @@ -1725,7 +1727,6 @@ class TComponent $exprops[] = "\0TComponent\0_e"; if ($this->_m===null) $exprops[] = "\0TComponent\0_m"; - return array_diff($a,$exprops); } } diff --git a/framework/Web/UI/TControl.php b/framework/Web/UI/TControl.php index 055b5521..afe1daa3 100644 --- a/framework/Web/UI/TControl.php +++ b/framework/Web/UI/TControl.php @@ -769,13 +769,19 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable { if($this->_trackViewState) { - $this->_viewState[$key]=$value; unset($this->_tempState[$key]); + if($value===$defaultValue) + unset($this->_viewState[$key]); + else + $this->_viewState[$key]=$value; } else { unset($this->_viewState[$key]); - $this->_tempState[$key]=$value; + if($value===$defaultValue) + unset($this->_tempState[$key]); + else + $this->_tempState[$key]=$value; } } @@ -1655,7 +1661,10 @@ class TControl extends TApplicationComponent implements IRenderable, IBindable foreach($this->_rf[self::RF_CONTROLS] as $control) { if($control instanceof TControl) - $state[$control->_id]=&$control->saveStateRecursive($needViewState); + { + if(count($tmp = &$control->saveStateRecursive($needViewState))) + $state[$control->_id]=$tmp; + } } } if($needViewState && !empty($this->_viewState)) diff --git a/framework/Web/UI/WebControls/TDataGridPagerStyle.php b/framework/Web/UI/WebControls/TDataGridPagerStyle.php index b96d0cd2..36d55ba9 100644 --- a/framework/Web/UI/WebControls/TDataGridPagerStyle.php +++ b/framework/Web/UI/WebControls/TDataGridPagerStyle.php @@ -32,6 +32,35 @@ class TDataGridPagerStyle extends TPanelStyle private $_visible=null; private $_buttonType=null; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_mode===null) + $exprops[] = "\0TDataGridPagerStyle\0_mode"; + if ($this->_nextText===null) + $exprops[] = "\0TDataGridPagerStyle\0_nextText"; + if ($this->_prevText===null) + $exprops[] = "\0TDataGridPagerStyle\0_prevText"; + if ($this->_firstText===null) + $exprops[] = "\0TDataGridPagerStyle\0_firstText"; + if ($this->_lastText===null) + $exprops[] = "\0TDataGridPagerStyle\0_lastText"; + if ($this->_buttonCount===null) + $exprops[] = "\0TDataGridPagerStyle\0_buttonCount"; + if ($this->_position===null) + $exprops[] = "\0TDataGridPagerStyle\0_position"; + if ($this->_visible===null) + $exprops[] = "\0TDataGridPagerStyle\0_visible"; + if ($this->_buttonType===null) + $exprops[] = "\0TDataGridPagerStyle\0_buttonType"; + } + /** * @return TDataGridPagerMode pager mode. Defaults to TDataGridPagerMode::NextPrev. */ diff --git a/framework/Web/UI/WebControls/TFont.php b/framework/Web/UI/WebControls/TFont.php index 52a5db71..ab09c58e 100644 --- a/framework/Web/UI/WebControls/TFont.php +++ b/framework/Web/UI/WebControls/TFont.php @@ -53,6 +53,23 @@ class TFont extends TComponent */ private $_size=''; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_flags===0) + $exprops[] = "\0TFont\0_flags"; + if ($this->_name==='') + $exprops[] = "\0TFont\0_name"; + if ($this->_size==='') + $exprops[] = "\0TFont\0_size"; + } + /** * @return boolean whether the font is in bold face. Defaults to false. */ diff --git a/framework/Web/UI/WebControls/TLabel.php b/framework/Web/UI/WebControls/TLabel.php index bf43b4d2..28b0ffd4 100644 --- a/framework/Web/UI/WebControls/TLabel.php +++ b/framework/Web/UI/WebControls/TLabel.php @@ -102,7 +102,7 @@ class TLabel extends TWebControl implements IDataRenderer */ public function setText($value) { - $this->setViewState('Text',$value,''); + $this->setViewState('Text',TPropertyValue::ensureString($value),''); } /** diff --git a/framework/Web/UI/WebControls/TListItem.php b/framework/Web/UI/WebControls/TListItem.php index aec006db..5a9122d6 100644 --- a/framework/Web/UI/WebControls/TListItem.php +++ b/framework/Web/UI/WebControls/TListItem.php @@ -32,19 +32,19 @@ class TListItem extends TComponent /** * @var string text of the item */ - private $_text; + private $_text=''; /** * @var string value of the item */ - private $_value; + private $_value=''; /** * @var boolean whether the item is enabled */ - private $_enabled; + private $_enabled=true; /** * @var boolean whether the item is selected */ - private $_selected; + private $_selected=false; /** * Constructor. @@ -61,6 +61,27 @@ class TListItem extends TComponent $this->setSelected($selected); } + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_attributes===null) + $exprops[] = "\0TListItem\0_attributes"; + if($this->_text==='') + $exprops[] = "\0TListItem\0_text"; + if($this->_value==='') + $exprops[] = "\0TListItem\0_value"; + if ($this->_enabled===true) + $exprops[] = "\0TListItem\0_enabled"; + if ($this->_selected===false) + $exprops[] = "\0TListItem\0_selected"; + } + /** * @return boolean whether the item is enabled */ diff --git a/framework/Web/UI/WebControls/TLiteral.php b/framework/Web/UI/WebControls/TLiteral.php index f2306b4b..650ed070 100644 --- a/framework/Web/UI/WebControls/TLiteral.php +++ b/framework/Web/UI/WebControls/TLiteral.php @@ -45,7 +45,7 @@ class TLiteral extends TControl implements IDataRenderer */ public function setText($value) { - $this->setViewState('Text',$value,''); + $this->setViewState('Text',TPropertyValue::ensureString($value),''); } /** diff --git a/framework/Web/UI/WebControls/TPanelStyle.php b/framework/Web/UI/WebControls/TPanelStyle.php index 2e0f1a2a..a3558dc7 100644 --- a/framework/Web/UI/WebControls/TPanelStyle.php +++ b/framework/Web/UI/WebControls/TPanelStyle.php @@ -45,6 +45,27 @@ class TPanelStyle extends TStyle */ private $_wrap=null; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_backImageUrl===null) + $exprops[] = "\0TPanelStyle\0_backImageUrl"; + if ($this->_direction===null) + $exprops[] = "\0TPanelStyle\0_direction"; + if ($this->_horizontalAlign===null) + $exprops[] = "\0TPanelStyle\0_horizontalAlign"; + if ($this->_scrollBars===null) + $exprops[] = "\0TPanelStyle\0_scrollBars"; + if ($this->_wrap===null) + $exprops[] = "\0TPanelStyle\0_wrap"; + } + /** * Adds attributes related to CSS styles to renderer. * This method overrides the parent implementation. diff --git a/framework/Web/UI/WebControls/TStyle.php b/framework/Web/UI/WebControls/TStyle.php index eb47f2f7..552a3786 100644 --- a/framework/Web/UI/WebControls/TStyle.php +++ b/framework/Web/UI/WebControls/TStyle.php @@ -46,6 +46,27 @@ class TStyle extends TComponent */ private $_displayStyle='Fixed'; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_fields===array()) + $exprops[] = "\0TStyle\0_fields"; + if($this->_font===null) + $exprops[] = "\0TStyle\0_font"; + if($this->_class===null) + $exprops[] = "\0TStyle\0_class"; + if ($this->_customStyle===null) + $exprops[] = "\0TStyle\0_customStyle"; + if ($this->_displayStyle==='Fixed') + $exprops[] = "\0TStyle\0_displayStyle"; + } + /** * Constructor. * @param TStyle style to copy from @@ -462,6 +483,29 @@ class TTableStyle extends TStyle */ private $_borderCollapse=null; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_backImageUrl===null) + $exprops[] = "\0TTableStyle\0_backImageUrl"; + if ($this->_horizontalAlign===null) + $exprops[] = "\0TTableStyle\0_horizontalAlign"; + if ($this->_cellPadding===null) + $exprops[] = "\0TTableStyle\0_cellPadding"; + if ($this->_cellSpacing===null) + $exprops[] = "\0TTableStyle\0_cellSpacing"; + if ($this->_gridLines===null) + $exprops[] = "\0TTableStyle\0_gridLines"; + if ($this->_borderCollapse===null) + $exprops[] = "\0TTableStyle\0_borderCollapse"; + } + /** * Sets the style attributes to default values. * This method overrides the parent implementation by @@ -690,6 +734,23 @@ class TTableItemStyle extends TStyle */ private $_wrap=null; + /** + * Returns an array with the names of all variables of this object that should NOT be serialized + * because their value is the default one or useless to be cached for the next page loads. + * Reimplement in derived classes to add new variables, but remember to also to call the parent + * implementation first. + */ + protected function __getZappableSleepProps(&$exprops) + { + parent::__getZappableSleepProps($exprops); + if ($this->_horizontalAlign===null) + $exprops[] = "\0TTableItemStyle\0_horizontalAlign"; + if ($this->_verticalAlign===null) + $exprops[] = "\0TTableItemStyle\0_verticalAlign"; + if ($this->_wrap===null) + $exprops[] = "\0TTableItemStyle\0_wrap"; + } + /** * Sets the style attributes to default values. * This method overrides the parent implementation by diff --git a/framework/Web/UI/WebControls/TTextBox.php b/framework/Web/UI/WebControls/TTextBox.php index f3a0c166..cd7b1c57 100644 --- a/framework/Web/UI/WebControls/TTextBox.php +++ b/framework/Web/UI/WebControls/TTextBox.php @@ -478,7 +478,7 @@ class TTextBox extends TWebControl implements IPostBackDataHandler, IValidatable */ public function setText($value) { - $this->setViewState('Text',$value,''); + $this->setViewState('Text',TPropertyValue::ensureString($value),''); $this->_safeText = null; } -- cgit v1.2.3