From fbb45df47d84e6a5145407ded1fdde4a85d6421f Mon Sep 17 00:00:00 2001 From: Daniil Gentili Date: Sun, 22 May 2022 14:15:00 +0200 Subject: [PATCH] Cache FFI --- composer.json | 17 +++++++++++++++-- lib/danog/PrimeModule.php | 5 +++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 017d10f..7447076 100644 --- a/composer.json +++ b/composer.json @@ -10,14 +10,27 @@ } ], "require": { - "php": ">=7.0" + "php": "^8.0" }, "suggest": { - "ext-primemodule": "Install the native C++ extension for extremely fast factorization (https://github.com/danog/PrimeModule-ext)" + "ext-primemodule": "Install the native C++ extension for extremely fast factorization (https://prime.madelineproto.xyz)" }, "autoload": { "psr-0": { "danog\\": "lib/" } + }, + "config": { + "allow-plugins": { + "phabel/phabel": true + } + }, + "require-dev": { + "phabel/phabel": "^1" + }, + "extra": { + "phabel": { + "revision": 0 + } } } diff --git a/lib/danog/PrimeModule.php b/lib/danog/PrimeModule.php index f2afacc..0a11ec2 100644 --- a/lib/danog/PrimeModule.php +++ b/lib/danog/PrimeModule.php @@ -218,13 +218,14 @@ class PrimeModule return $res; } + private static ?FFI $ffi = null; public static function native_single_cpp($what) { if (!extension_loaded('primemodule')) { if (class_exists(FFI::class)) { try { - $ffi = FFI::load('/usr/include/primemodule-ffi.h'); - $result = $ffi->factorizeFFI((string) $what); + self::$ffi = FFI::load('/usr/include/primemodule-ffi.h'); + $result = self::$ffi->factorizeFFI((string) $what); if ($result > 0) { return $result; }