Skip to content

Commit 76abd90

Browse files
committed
Inline compression and decompression instead of delegating
1 parent 8f5a6f8 commit 76abd90

File tree

3 files changed

+3
-11
lines changed

3 files changed

+3
-11
lines changed

src/main/php/com/mongodb/io/Compressor.class.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@ public function __construct(int $id, Algorithm $algorithm, $options= null) {
1212
$this->options= $options;
1313
}
1414

15-
public function compress($data) {
16-
return $this->algorithm->compress($data, $this->options);
17-
}
18-
19-
public function decompress($compressed) {
20-
return $this->algorithm->decompress($compressed);
21-
}
22-
2315
public function toString() { return nameof($this).'(id: '.$this->id.', options: '.$this->options.')'; }
2416

2517
public function hashCode() { return 'C'.$this->id; }

src/main/php/com/mongodb/io/Connection.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ public function send($operation, $header, $sections, $readPreference= null) {
239239
$length= strlen($body);
240240

241241
if ($this->compression && $compressor= $this->compression->for($sections, $length)) {
242-
$compressed= $compressor->compress($body);
242+
$compressed= $compressor->algorithm->compress($body, $compressor->options);
243243
$this->socket->write(pack(
244244
'VVVVVVCa*',
245245
strlen($compressed) + 25,
@@ -284,7 +284,7 @@ public function send($operation, $header, $sections, $readPreference= null) {
284284
$compressed= unpack('VoriginalOpcode/VuncompressedSize/CcompressorId', $response);
285285

286286
if ($this->compression && $compressor= $this->compression->select($compressed['compressorId'] ?? null)) {
287-
$response= $compressor->decompress(substr($response, 9));
287+
$response= $compressor->algorithm->decompress(substr($response, 9));
288288
$meta['opCode']= $compressed['originalOpcode'];
289289
goto opcode;
290290
}

src/test/php/com/mongodb/unittest/ConnectionTest.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ private function msg(array $document): array {
3232
/** Creates an OP_COMPRESSED message with an embedded OP_MSG opcode */
3333
private function compressed(Compressor $compressor, array $document): array {
3434
$payload= pack('VC', 0, 0).$this->bson->sections($document);
35-
$compressed= $compressor->compress($payload);
35+
$compressed= $compressor->algorithm->compress($payload, $compressor->options);
3636
return [
3737
pack('VVVV', strlen($compressed) + 25, 0, 0, Connection::OP_COMPRESSED),
3838
pack('VVC', Connection::OP_MSG, strlen($payload), $compressor->id).$compressed

0 commit comments

Comments
 (0)