Skip to content

Commit 362a76b

Browse files
committed
Improving performance of YAML storage
1 parent 571a1f6 commit 362a76b

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/VCR/Storage/Yaml.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -75,14 +75,12 @@ private function readNextRecord()
7575

7676
$isInRecord = false;
7777
$recording = '';
78-
$lastChar = null;
7978

80-
while (false !== ($char = fgetc($this->handle))) {
81-
$isNewArrayStart = ($char === '-') && ($lastChar === "\n" || $lastChar === null);
82-
$lastChar = $char;
79+
while (false !== ($line = fgets($this->handle))) {
80+
$isNewArrayStart = strpos($line, '-') === 0;
8381

8482
if ($isInRecord && $isNewArrayStart) {
85-
fseek($this->handle, -1, SEEK_CUR);
83+
fseek($this->handle, -strlen($line), SEEK_CUR);
8684
break;
8785
}
8886

@@ -91,11 +89,11 @@ private function readNextRecord()
9189
}
9290

9391
if ($isInRecord) {
94-
$recording .= $char;
92+
$recording .= $line;
9593
}
9694
}
9795

98-
if ($char == false) {
96+
if ($line == false) {
9997
$this->isEOF = true;
10098
}
10199

0 commit comments

Comments
 (0)