Skip to content

Commit 8eb624f

Browse files
committed
Improved the checkedWrite performance
1 parent 08d325c commit 8eb624f

File tree

1 file changed

+2
-5
lines changed

1 file changed

+2
-5
lines changed

src/Persistence/IndexSerializer.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,11 +300,8 @@ public function readBm25(string $path): array
300300
*/
301301
private function checkedWrite($fh, string $data): void
302302
{
303-
$len = strlen($data);
304-
$written = fwrite($fh, $data);
305-
306-
if ($written !== $len) {
307-
throw new \RuntimeException("Failed to write {$len} bytes (wrote " . ($written === false ? '0' : $written) . ')');
303+
if (@fwrite($fh, $data) === false) {
304+
throw new \RuntimeException("Failed to write data");
308305
}
309306
}
310307
}

0 commit comments

Comments
 (0)