mirror of
https://github.com/bitcoin-s/bitcoin-s.git
synced 2025-03-26 13:25:49 +01:00
Small optimization for ScriptOperationFactory.operations (#1450)
* Small optimization for ScriptOperationFactory.operations * Make operations a val
This commit is contained in:
parent
05a411ccab
commit
11255390d2
2 changed files with 12 additions and 11 deletions
|
@ -1,6 +1,5 @@
|
|||
package org.bitcoins.core.script
|
||||
|
||||
import org.bitcoins.core.script.ScriptOperation.operations
|
||||
import org.bitcoins.core.script.arithmetic.ArithmeticOperation
|
||||
import org.bitcoins.core.script.bitwise.BitwiseOperation
|
||||
import org.bitcoins.core.script.constant._
|
||||
|
@ -66,7 +65,7 @@ trait ScriptOperationFactory[T <: ScriptOperation] extends BitcoinSLogger {
|
|||
}
|
||||
}
|
||||
private lazy val scriptOpMap: Map[Byte, ScriptOperation] = {
|
||||
operations.map(o => (o.toByte,o)).toMap
|
||||
operations.map(o => (o.toByte, o)).toMap
|
||||
}
|
||||
def apply(byte: Byte): T = fromByte(byte)
|
||||
|
||||
|
@ -76,12 +75,12 @@ trait ScriptOperationFactory[T <: ScriptOperation] extends BitcoinSLogger {
|
|||
object ScriptOperation extends ScriptOperationFactory[ScriptOperation] {
|
||||
|
||||
/** This contains duplicate operations
|
||||
* There is an optimization here by moving popular opcodes
|
||||
* to the front of the vector so when we iterate through it,
|
||||
* we are more likely to find the op code we are looking for
|
||||
* sooner */
|
||||
* There is an optimization here by moving popular opcodes
|
||||
* to the front of the vector so when we iterate through it,
|
||||
* we are more likely to find the op code we are looking for
|
||||
* sooner */
|
||||
final override val operations: Vector[ScriptOperation] = {
|
||||
Vector(OP_FALSE, OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4, OP_TRUE) ++
|
||||
StackPushOperationFactory.pushDataOperations ++
|
||||
StackOperation.operations ++
|
||||
LocktimeOperation.operations ++
|
||||
CryptoOperation.operations ++
|
||||
|
@ -91,7 +90,7 @@ object ScriptOperation extends ScriptOperationFactory[ScriptOperation] {
|
|||
BytesToPushOntoStack.operations ++
|
||||
SpliceOperation.operations ++
|
||||
ReservedOperation.operations ++
|
||||
ScriptNumberOperation.operations
|
||||
ScriptNumberOperation.operations
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,9 @@ trait StackPushOperationFactory {
|
|||
*/
|
||||
def isPushOperation(token: ScriptToken): Boolean = operations.contains(token)
|
||||
|
||||
val pushDataOperations: Vector[ScriptOperation] =
|
||||
Vector(OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4)
|
||||
|
||||
/**
|
||||
* Gives back all of the script operations that can push data onto the stack
|
||||
* The operations are determined according to BIP62
|
||||
|
@ -20,8 +23,8 @@ trait StackPushOperationFactory {
|
|||
*
|
||||
* @return
|
||||
*/
|
||||
private def operations =
|
||||
Seq(OP_PUSHDATA1, OP_PUSHDATA2, OP_PUSHDATA4) ++ BytesToPushOntoStack.operations ++
|
||||
private val operations =
|
||||
pushDataOperations ++ BytesToPushOntoStack.operations ++
|
||||
Seq(OP_0,
|
||||
OP_1,
|
||||
OP_1NEGATE,
|
||||
|
@ -42,7 +45,6 @@ trait StackPushOperationFactory {
|
|||
OP_16,
|
||||
OP_FALSE,
|
||||
OP_TRUE)
|
||||
|
||||
}
|
||||
|
||||
object StackPushOperationFactory extends StackPushOperationFactory
|
||||
|
|
Loading…
Add table
Reference in a new issue