RegistryTrait: added fast path optimization

this reduces VanillaBlocks access time from 360 ns to 230 ns on my machine - an improvement of about 35%.
This commit is contained in:
Dylan K. Taylor 2024-03-13 17:11:06 +00:00
parent 9f3533d870
commit 1de66cb0de
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -114,6 +114,13 @@ trait RegistryTrait{
if(count($arguments) > 0){ if(count($arguments) > 0){
throw new \ArgumentCountError("Expected exactly 0 arguments, " . count($arguments) . " passed"); throw new \ArgumentCountError("Expected exactly 0 arguments, " . count($arguments) . " passed");
} }
//fast path
if(self::$members !== null && isset(self::$members[$name])){
return self::preprocessMember(self::$members[$name]);
}
//fallback
try{ try{
return self::_registryFromString($name); return self::_registryFromString($name);
}catch(\InvalidArgumentException $e){ }catch(\InvalidArgumentException $e){