Skip to content

Commit e787a1f

Browse files
author
Anton Kuznetsov
committed
Optimized dictZip
1 parent b85873e commit e787a1f

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/GPT3Encoder/Gpt3Encoder.php

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,16 @@ private function myFilter($var): bool
134134

135135
private function dictZip(array $x): array
136136
{
137-
$result = [];
138-
$cnt = 0;
139-
foreach ($x as $i) {
140-
if (isset($i[1], $i[0])) {
141-
$result[$i[0] . ',' . $i[1]] = $cnt;
142-
$cnt++;
137+
if (!$result = $this->cache->get('dictZip')) {
138+
$result = [];
139+
$cnt = 0;
140+
foreach ($x as $i) {
141+
if (isset($i[1], $i[0])) {
142+
$result[$i[0] . ',' . $i[1]] = $cnt;
143+
$cnt++;
144+
}
143145
}
146+
$this->cache->set('dictZip', $result);
144147
}
145148
return $result;
146149

0 commit comments

Comments
 (0)