[Serializer] improved CsvEncoder::decode performance by caching duplicate count calls
This commit is contained in:
parent
5b8cf03dcb
commit
3b910a9fad
@ -115,6 +115,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
||||
|
||||
$headers = null;
|
||||
$nbHeaders = 0;
|
||||
$headerCount = array();
|
||||
$result = array();
|
||||
|
||||
list($delimiter, $enclosure, $escapeChar, $keySeparator) = $this->getCsvOptions($context);
|
||||
@ -126,7 +127,9 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
||||
$nbHeaders = $nbCols;
|
||||
|
||||
foreach ($cols as $col) {
|
||||
$headers[] = explode($keySeparator, $col);
|
||||
$header = explode($keySeparator, $col);
|
||||
$headers[] = $header;
|
||||
$headerCount[] = count($header);
|
||||
}
|
||||
|
||||
continue;
|
||||
@ -134,7 +137,7 @@ class CsvEncoder implements EncoderInterface, DecoderInterface
|
||||
|
||||
$item = array();
|
||||
for ($i = 0; ($i < $nbCols) && ($i < $nbHeaders); ++$i) {
|
||||
$depth = count($headers[$i]);
|
||||
$depth = $headerCount[$i];
|
||||
$arr = &$item;
|
||||
for ($j = 0; $j < $depth; ++$j) {
|
||||
// Handle nested arrays
|
||||
|
Reference in New Issue
Block a user