mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-12 14:35:35 +00:00
CraftingManager: micro optimization: reuse closure for item deserialize & reduce indirection
This commit is contained in:
parent
2a5561fcd1
commit
6161155660
@ -53,6 +53,7 @@ class CraftingManager{
|
|||||||
public function init() : void{
|
public function init() : void{
|
||||||
$recipes = json_decode(file_get_contents(\pocketmine\RESOURCE_PATH . "vanilla" . DIRECTORY_SEPARATOR . "recipes.json"), true);
|
$recipes = json_decode(file_get_contents(\pocketmine\RESOURCE_PATH . "vanilla" . DIRECTORY_SEPARATOR . "recipes.json"), true);
|
||||||
|
|
||||||
|
$itemDeserializerFunc = \Closure::fromCallable([Item::class, 'jsonDeserialize']);
|
||||||
foreach($recipes as $recipe){
|
foreach($recipes as $recipe){
|
||||||
switch($recipe["type"]){
|
switch($recipe["type"]){
|
||||||
case "shapeless":
|
case "shapeless":
|
||||||
@ -60,8 +61,8 @@ class CraftingManager{
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
$this->registerRecipe(new ShapelessRecipe(
|
$this->registerRecipe(new ShapelessRecipe(
|
||||||
array_map(function(array $data) : Item{ return Item::jsonDeserialize($data); }, $recipe["input"]),
|
array_map($itemDeserializerFunc, $recipe["input"]),
|
||||||
array_map(function(array $data) : Item{ return Item::jsonDeserialize($data); }, $recipe["output"])
|
array_map($itemDeserializerFunc, $recipe["output"])
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case "shaped":
|
case "shaped":
|
||||||
@ -70,8 +71,8 @@ class CraftingManager{
|
|||||||
}
|
}
|
||||||
$this->registerRecipe(new ShapedRecipe(
|
$this->registerRecipe(new ShapedRecipe(
|
||||||
$recipe["shape"],
|
$recipe["shape"],
|
||||||
array_map(function(array $data) : Item{ return Item::jsonDeserialize($data); }, $recipe["input"]),
|
array_map($itemDeserializerFunc, $recipe["input"]),
|
||||||
array_map(function(array $data) : Item{ return Item::jsonDeserialize($data); }, $recipe["output"])
|
array_map($itemDeserializerFunc, $recipe["output"])
|
||||||
));
|
));
|
||||||
break;
|
break;
|
||||||
case "smelting":
|
case "smelting":
|
||||||
|
Loading…
x
Reference in New Issue
Block a user