1
0
mirror of https://github.com/shuchkin/simplexlsxgen.git synced 2023-08-10 21:12:59 +03:00

Merge pull request #4 from fredriksundin/performance

Replace array_search to optimize large arrays
This commit is contained in:
Sergey Shuchkin 2020-08-21 21:40:15 +06:00 committed by GitHub
commit 9824e5b25d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -162,6 +162,7 @@ class SimpleXLSXGen {
} }
$SI = []; $SI = [];
$SI_KEYS = [];
$COLS = []; $COLS = [];
$ROWS = []; $ROWS = [];
if ( count($this->rows) ) { if ( count($this->rows) ) {
@ -212,10 +213,15 @@ class SimpleXLSXGen {
} else { } else {
$ct = 's'; // shared string $ct = 's'; // shared string
$v = str_replace(['&','<','>'],['&amp;','&lt;','&gt;'], $v); $v = str_replace(['&','<','>'],['&amp;','&lt;','&gt;'], $v);
$cv = array_search( $v, $SI, true ); $cv = false;
if ( isset($SI_KEYS[$v]) && $SI[$SI_KEYS[$v]] === $v ) {
$cv = $SI_KEYS[$v];
}
if ( $cv === false ) { if ( $cv === false ) {
$SI[] = $v; $SI[] = $v;
$cv = count( $SI ) - 1; $cv = count( $SI ) - 1;
$SI_KEYS[$v] = $cv;
} }
} }
} elseif ( is_int( $v ) || is_float( $v ) ) { } elseif ( is_int( $v ) || is_float( $v ) ) {