Skip to content

Commit 9f40267

Browse files
committed
Optimized EnumSet::count() and EnumSet::getOrdinals()
1 parent 78aa96b commit 9f40267

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/EnumSet.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,9 @@ public function count()
184184
continue; // fast skip null byte
185185
}
186186

187+
$ord = ord($this->bitset[$bytePos]);
187188
for ($bitPos = 0; $bitPos < 8; ++$bitPos) {
188-
if ((ord($this->bitset[$bytePos]) & (1 << $bitPos)) !== 0) {
189+
if ($ord & (1 << $bitPos)) {
189190
++$count;
190191
}
191192
}
@@ -347,8 +348,9 @@ public function getOrdinals()
347348
continue; // fast skip null byte
348349
}
349350

351+
$ord = ord($this->bitset[$bytePos]);
350352
for ($bitPos = 0; $bitPos < 8; ++$bitPos) {
351-
if ((ord($this->bitset[$bytePos]) & (1 << $bitPos)) !== 0) {
353+
if ($ord & (1 << $bitPos)) {
352354
$ordinals[] = $bytePos * 8 + $bitPos;
353355
}
354356
}

0 commit comments

Comments
 (0)