-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Search style by identity in PHPExcel_Worksheet::duplicateStyle() #84
Search style by identity in PHPExcel_Worksheet::duplicateStyle() #84
Conversation
Search style by identity in PHPExcel_Worksheet::duplicateStyle()
Thanks: A nice performance boost, and the PHPExcel::cellXfExists() call can also be used in the applyFromArray() method of PHPExcel_Style as well. |
For applyFromArray() this technique is not applicable. Cloned $newStyle is new object and cellXfExists() will always return false. |
In my use case, this fix causes memory exhaust.
|
Describe your use case. How do you create new styles? Once in program like in 40duplicateStyle.php or every time before duplicateStyle()? |
My use is 'row copy' like following:
Actually I'm also confused that your fix has introduced lack of consistency in equality comparison. |
I adopted an altenative way to boost applyFromArray(), Replace getHashCode() by following getEqualCellXf().
|
It is better to extend the interface of PHPExcel_IComparable with equals() method and use it for styles searching. In general use getHashCode() for equality is very strange. |
Thank you for your fix. |
Increases duplicateStyle performance.
Run Examples/40duplicateStyle.php.
before
[Examples]$ php 40duplicateStyle.php
08:35:05 Create new PHPExcel object
08:35:05 Create styles array
08:35:05 Add data (begin)
08:35:18 Add data (end), time: 12.96 s
08:35:18 Write to Excel2007 format
08:35:20 File written to 40duplicateStyle.xlsx
08:35:20 Peak memory usage: 12 MB
08:35:20 Done writing file
File has been created in /builddir/PHPExcel/Examples
after
[Examples]$ php 40duplicateStyle.php
08:36:19 Create new PHPExcel object
08:36:19 Create styles array
08:36:19 Add data (begin)
08:36:23 Add data (end), time: 3.27 s
08:36:23 Write to Excel2007 format
08:36:25 File written to 40duplicateStyle.xlsx
08:36:25 Peak memory usage: 12 MB
08:36:25 Done writing file
File has been created in /builddir/PHPExcel/Examples