Quantcast
Channel: PHPExcel Forum Rss Feed
Viewing all articles
Browse latest Browse all 2707

New Post: Speed fix - takes memory - is it right?

$
0
0
Hello,

a quick (dirty) fix to greatly speedup styles assignment. What do you think about it?

The method getCellXfByHashCode() is awfully slow, so I tried to replace it with a cache array.

version: 1.8.0
file: PHPExcel/Style.php
method: applyFromArray()

new code:
global $__cache;
if (!isset($__cache)) {
    $__cache = array();
}

        $hashCode = $newStyle->getHashCode();
        if (isset($__cache[$hashCode])) {
            $newXfIndexes[$oldXfIndex] = $__cache[$hashCode];
        } else {
            // we don't have such a cell Xf, need to add
            $workbook->addCellXf($newStyle);
            $newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
            $__cache[$hashCode] = $newStyle->getIndex();
        }
old code:
if ($existingStyle = $workbook->getCellXfByHashCode($newStyle->getHashCode())) {
    $newXfIndexes[$oldXfIndex] = $existingStyle->getIndex();
} else {
    // we don't have such a cell Xf, need to add
    $workbook->addCellXf($newStyle);
    $newXfIndexes[$oldXfIndex] = $newStyle->getIndex();
}

Viewing all articles
Browse latest Browse all 2707

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>