Skip to content

Commit 18381bf

Browse files
author
Roman Orlov
committed
[Serializer] improved CsvEncoder::decode performance by caching duplicate count calls
1 parent ac3e016 commit 18381bf

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

Encoder/CsvEncoder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public function decode($data, $format, array $context = array())
115115

116116
$headers = null;
117117
$nbHeaders = 0;
118+
$headerCount = array();
118119
$result = array();
119120

120121
list($delimiter, $enclosure, $escapeChar, $keySeparator) = $this->getCsvOptions($context);
@@ -126,15 +127,17 @@ public function decode($data, $format, array $context = array())
126127
$nbHeaders = $nbCols;
127128

128129
foreach ($cols as $col) {
129-
$headers[] = explode($keySeparator, $col);
130+
$header = explode($keySeparator, $col);
131+
$headers[] = $header;
132+
$headerCount[] = count($header);
130133
}
131134

132135
continue;
133136
}
134137

135138
$item = array();
136139
for ($i = 0; ($i < $nbCols) && ($i < $nbHeaders); ++$i) {
137-
$depth = count($headers[$i]);
140+
$depth = $headerCount[$i];
138141
$arr = &$item;
139142
for ($j = 0; $j < $depth; ++$j) {
140143
// Handle nested arrays

0 commit comments

Comments
 (0)