Skip to content

Commit 39188c3

Browse files
author
Indrek Altpere
committed
Optimized versions of uint16 and int16 multi-readers
1 parent 835a188 commit 39188c3

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/FontLib/BinaryStream.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,10 @@ public function readUInt16() {
185185
return $a["n"];
186186
}
187187

188+
public function readUInt16Many($count) {
189+
return array_values(unpack("n*", $this->read($count * 2)));
190+
}
191+
188192
public function readUFWord() {
189193
return $this->readUInt16();
190194
}
@@ -207,6 +211,17 @@ public function readInt16() {
207211
return $v;
208212
}
209213

214+
public function readInt16Many($count) {
215+
$vals = array_values(unpack("n*", $this->read($count * 2)));
216+
foreach ($vals as &$v) {
217+
if ($v >= 0x8000) {
218+
$v -= 0x10000;
219+
}
220+
}
221+
222+
return $vals;
223+
}
224+
210225
public function readFWord() {
211226
return $this->readInt16();
212227
}

0 commit comments

Comments
 (0)