Skip to content

Commit

Permalink
Merge pull request #267 from samsonasik/use-spl-object-id
Browse files Browse the repository at this point in the history
Improve performance by using `spl_object_id()` on PHP 7.2+
  • Loading branch information
SimonFrings committed Oct 25, 2023
2 parents c0ae01e + 4a8f6af commit 67f4642
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 67f4642

Please sign in to comment.