Skip to content

Commit 0e1b92e

Browse files
committed
Dramatically reduce total number of method calls in PHP writer
This does have an actual impact on the runtime of code that uses this, e.g. MessageIndexTest in the Translate extension. Change-Id: I67a1b060960f4102379632350f1ecba055e5211c
1 parent d5f39df commit 0e1b92e

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/Writer/PHP.php

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,7 @@ public function set( $key, $value ): void {
7272
return;
7373
}
7474
$this->addbegin( strlen( $key ), strlen( $value ) );
75-
$this->write( $key );
76-
$this->write( $value );
75+
$this->write( $key . $value );
7776
$this->addend( strlen( $key ), strlen( $value ), Util::hash( $key ) );
7877
}
7978

@@ -126,9 +125,7 @@ protected function addend( $keylen, $datalen, $h ) {
126125
];
127126

128127
$this->numentries++;
129-
$this->posplus( 8 );
130-
$this->posplus( $keylen );
131-
$this->posplus( $datalen );
128+
$this->posplus( 8 + $keylen + $datalen );
132129
}
133130

134131
/**
@@ -207,14 +204,15 @@ protected function finish(): void {
207204
}
208205

209206
// Write the hashtable
207+
$buf = '';
210208
for ( $u = 0; $u < $len; ++$u ) {
211-
$buf = pack( 'vvV',
209+
$buf .= pack( 'vvV',
212210
$hashtable[$u]['h'] & 0xffff,
213211
Util::unsignedShiftRight( $hashtable[$u]['h'], 16 ),
214212
$hashtable[$u]['p'] );
215-
$this->write( $buf );
216-
$this->posplus( 8 );
217213
}
214+
$this->write( $buf );
215+
$this->posplus( strlen( $buf ) );
218216
}
219217

220218
// Write the pointer array at the start of the file

0 commit comments

Comments
 (0)