From 11bf2138ba8977eebfa7355823380b95471b9a60 Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 27 Aug 2023 10:46:42 +0200 Subject: [PATCH] Performance improvements --- docs | 2 +- src/EventHandler.php | 16 +++++++++------- vendor-bin/check/composer.json | 2 +- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/docs b/docs index 2252db95c..f855706e1 160000 --- a/docs +++ b/docs @@ -1 +1 @@ -Subproject commit 2252db95c03cbc54588a9368fa96d9cb910cb33d +Subproject commit f855706e1b65ce6b4c5a6babed5928a138d10f56 diff --git a/src/EventHandler.php b/src/EventHandler.php index 60602bc84..2ca660928 100644 --- a/src/EventHandler.php +++ b/src/EventHandler.php @@ -164,7 +164,7 @@ abstract class EventHandler extends AbstractAPI $method_name = \lcfirst(\substr($method, 2)); if (($constructor = $constructors->findByPredicate($method_name)) && $constructor['type'] === 'Update') { $methods[$method_name] = [ - function (array $update) use ($basic_handler, $closure): void { + static function (array $update) use ($basic_handler, $closure): void { EventLoop::queue($basic_handler, $update, $closure); } ]; @@ -179,7 +179,7 @@ abstract class EventHandler extends AbstractAPI } $periodic = $periodic[0]->newInstance(); $this->periodicLoops[$method] = new PeriodicLoop( - function (PeriodicLoop $loop) use ($closure): bool { + static function (PeriodicLoop $loop) use ($closure): bool { return $closure($loop) ?? false; }, $method, @@ -208,10 +208,12 @@ abstract class EventHandler extends AbstractAPI if (!$this instanceof SimpleEventHandler) { throw new AssertionError("Please extend SimpleEventHandler to use filters!"); } - $handlers []= function (Update $update) use ($closure, $filter): void { - if ($filter->apply($update)) { - EventLoop::queue($closure, $update); - } + $handlers []= static function (Update $update) use ($closure, $filter): void { + EventLoop::queue(static function () use ($closure, $filter, $update) { + if ($filter->apply($update)) { + $closure($update); + } + }); }; } if ($this instanceof SimpleEventHandler) { @@ -435,7 +437,7 @@ abstract class EventHandler extends AbstractAPI continue; } - \spl_autoload_register(function (string $class) use ($p): void { + \spl_autoload_register(static function (string $class) use ($p): void { if (!\str_starts_with($class, 'MadelinePlugin\\')) { return; } diff --git a/vendor-bin/check/composer.json b/vendor-bin/check/composer.json index efaa8359d..1079e020b 100644 --- a/vendor-bin/check/composer.json +++ b/vendor-bin/check/composer.json @@ -1,6 +1,6 @@ { "require": { - "psalm/phar": "^5", + "vimeo/psalm": "dev-master", "ennexa/amp-update-cache": "dev-master", "phpunit/phpunit": "^9", "amphp/php-cs-fixer-config": "v2.x-dev",