Skip to content

Commit 4a8f6af

Browse files
committed
[Performance] Use spl_object_id() when possible
1 parent f665998 commit 4a8f6af

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

src/Timer/Timers.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,21 @@ public function getTime()
3838

3939
public function add(TimerInterface $timer)
4040
{
41-
$id = \spl_object_hash($timer);
41+
$id = \PHP_VERSION_ID < 70200 ? \spl_object_hash($timer) : \spl_object_id($timer);
4242
$this->timers[$id] = $timer;
4343
$this->schedule[$id] = $timer->getInterval() + $this->updateTime();
4444
$this->sorted = false;
4545
}
4646

4747
public function contains(TimerInterface $timer)
4848
{
49-
return isset($this->timers[\spl_object_hash($timer)]);
49+
$id = \PHP_VERSION_ID < 70200 ? \spl_object_hash($timer) : \spl_object_id($timer);
50+
return isset($this->timers[$id]);
5051
}
5152

5253
public function cancel(TimerInterface $timer)
5354
{
54-
$id = \spl_object_hash($timer);
55+
$id = \PHP_VERSION_ID < 70200 ? \spl_object_hash($timer) : \spl_object_id($timer);
5556
unset($this->timers[$id], $this->schedule[$id]);
5657
}
5758

0 commit comments

Comments
 (0)