From 11255390d2948d648875b3b3f1c267a62c998961 Mon Sep 17 00:00:00 2001
From: Ben Carman <benthecarman@live.com>
Date: Wed, 20 May 2020 10:26:00 -0500
Subject: [PATCH] Small optimization for ScriptOperationFactory.operations
 (#1450)

* Small optimization for ScriptOperationFactory.operations

* Make operations a val
---
 .../core/script/ScriptOperationFactory.scala      | 15 +++++++--------
 .../constant/StackPushOperationFactory.scala      |  8 +++++---
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/core/src/main/scala/org/bitcoins/core/script/ScriptOperationFactory.scala b/core/src/main/scala/org/bitcoins/core/script/ScriptOperationFactory.scala
index 2f0e1c225b..a73f1543e9 100644
--- a/core/src/main/scala/org/bitcoins/core/script/ScriptOperationFactory.scala
+++ b/core/src/main/scala/org/bitcoins/core/script/ScriptOperationFactory.scala
@@ -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
   }
 
 }
diff --git a/core/src/main/scala/org/bitcoins/core/script/constant/StackPushOperationFactory.scala b/core/src/main/scala/org/bitcoins/core/script/constant/StackPushOperationFactory.scala
index 4030d778bc..e1ad9bdf38 100644
--- a/core/src/main/scala/org/bitcoins/core/script/constant/StackPushOperationFactory.scala
+++ b/core/src/main/scala/org/bitcoins/core/script/constant/StackPushOperationFactory.scala
@@ -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