From 20eec570ffe9ff1cb7cb1d57a66902d95850f2f6 Mon Sep 17 00:00:00 2001 From: Mark Baker Date: Tue, 14 Dec 2010 17:57:15 +0000 Subject: [PATCH] Minor performance/memory tweaks to the Excel2007 Writer git-svn-id: https://phpexcel.svn.codeplex.com/svn/trunk@65288 2327b42d-5241-43d6-9e2a-de5ac946f064 --- Classes/PHPExcel/Writer/Excel2007.php | 45 ++++++++++++++------------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/Classes/PHPExcel/Writer/Excel2007.php b/Classes/PHPExcel/Writer/Excel2007.php index 8c6f3995..c87de9b0 100644 --- a/Classes/PHPExcel/Writer/Excel2007.php +++ b/Classes/PHPExcel/Writer/Excel2007.php @@ -139,31 +139,34 @@ class PHPExcel_Writer_Excel2007 implements PHPExcel_Writer_IWriter // Set up disk caching location $this->_diskCachingDirectory = './'; - // Initialise writer parts - $this->_writerParts['stringtable'] = new PHPExcel_Writer_Excel2007_StringTable(); - $this->_writerParts['contenttypes'] = new PHPExcel_Writer_Excel2007_ContentTypes(); - $this->_writerParts['docprops'] = new PHPExcel_Writer_Excel2007_DocProps(); - $this->_writerParts['rels'] = new PHPExcel_Writer_Excel2007_Rels(); - $this->_writerParts['theme'] = new PHPExcel_Writer_Excel2007_Theme(); - $this->_writerParts['style'] = new PHPExcel_Writer_Excel2007_Style(); - $this->_writerParts['workbook'] = new PHPExcel_Writer_Excel2007_Workbook(); - $this->_writerParts['worksheet'] = new PHPExcel_Writer_Excel2007_Worksheet(); - $this->_writerParts['drawing'] = new PHPExcel_Writer_Excel2007_Drawing(); - $this->_writerParts['comments'] = new PHPExcel_Writer_Excel2007_Comments(); + $writerPartsArray = array( 'stringtable' => 'PHPExcel_Writer_Excel2007_StringTable', + 'contenttypes' => 'PHPExcel_Writer_Excel2007_ContentTypes', + 'docprops' => 'PHPExcel_Writer_Excel2007_DocProps', + 'rels' => 'PHPExcel_Writer_Excel2007_Rels', + 'theme' => 'PHPExcel_Writer_Excel2007_Theme', + 'style' => 'PHPExcel_Writer_Excel2007_Style', + 'workbook' => 'PHPExcel_Writer_Excel2007_Workbook', + 'worksheet' => 'PHPExcel_Writer_Excel2007_Worksheet', + 'drawing' => 'PHPExcel_Writer_Excel2007_Drawing', + 'comments' => 'PHPExcel_Writer_Excel2007_Comments' + ); - // Assign parent IWriter - foreach ($this->_writerParts as $writer) { - $writer->setParentWriter($this); + // Initialise writer parts + // and Assign their parent IWriters + foreach ($writerPartsArray as $writer => $class) { + $this->_writerParts[$writer] = new $class(); + $this->_writerParts[$writer]->setParentWriter($this); } + $hashTablesArray = array( '_stylesConditionalHashTable', '_fillHashTable', '_fontHashTable', + '_bordersHashTable', '_numFmtHashTable', '_drawingHashTable' + ); + // Set HashTable variables - $this->_stringTable = array(); - $this->_stylesConditionalHashTable = new PHPExcel_HashTable(); - $this->_fillHashTable = new PHPExcel_HashTable(); - $this->_fontHashTable = new PHPExcel_HashTable(); - $this->_bordersHashTable = new PHPExcel_HashTable(); - $this->_numFmtHashTable = new PHPExcel_HashTable(); - $this->_drawingHashTable = new PHPExcel_HashTable(); + $this->_stringTable = array(); + foreach ($hashTablesArray as $tableName) { + $this->$tableName = new PHPExcel_HashTable(); + } } /**