Skip to content

Commit 557da8c

Browse files
author
Thomas Kerin
committed
Reuse opcodes instances in ScriptFactory
1 parent 244c47f commit 557da8c

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Script/ScriptFactory.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ class ScriptFactory
2222
* @var OutputScriptFactory
2323
*/
2424
private static $outputScriptFactory = null;
25+
private static $opcodes = null;
26+
27+
private static function getOpCodes(): Opcodes
28+
{
29+
if (null === static::$opcodes) {
30+
static::$opcodes = new Opcodes();
31+
}
32+
return static::$opcodes;
33+
}
2534

2635
/**
2736
* @param string $string
@@ -52,7 +61,8 @@ public static function fromBuffer(BufferInterface $buffer, Opcodes $opcodes = nu
5261
*/
5362
public static function create(BufferInterface $buffer = null, Opcodes $opcodes = null, Math $math = null): ScriptCreator
5463
{
55-
return new ScriptCreator($math ?: Bitcoin::getMath(), $opcodes ?: new Opcodes(), $buffer);
64+
$opcodes = $opcodes ?: self::getOpCodes();
65+
return new ScriptCreator($math ?: Bitcoin::getMath(), $opcodes, $buffer);
5666
}
5767

5868
/**

0 commit comments

Comments
 (0)