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