Skip to content

Commit

Permalink
[Performance] Use spl_object_id() when possible
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Oct 21, 2023
1 parent f665998 commit 4a8f6af
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Timer/Timers.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,21 @@ public function getTime()

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

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

public function cancel(TimerInterface $timer)
{
$id = \spl_object_hash($timer);
$id = \PHP_VERSION_ID < 70200 ? \spl_object_hash($timer) : \spl_object_id($timer);
unset($this->timers[$id], $this->schedule[$id]);
}

Expand Down

0 comments on commit 4a8f6af

Please sign in to comment.