diff --git a/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java b/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java index 1d446b8117..ac292f0c49 100644 --- a/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java +++ b/src/main/java/io/lettuce/core/protocol/RedisStateMachine.java @@ -37,6 +37,7 @@ * @author Will Glozer * @author Mark Paluch * @author Helly Guo + * @author shikharid */ public class RedisStateMachine { @@ -225,9 +226,27 @@ public String toString() { return sb.toString(); } + void reset() { + this.type = null; + this.count = NOT_FOUND; + } + + /** + * Pre-allocates a State array of given len + * + * @param len len of the states array to be created + * @return array of State's of len size + */ + private static State[] createStates(int len) { + final State[] stack = new State[len]; + for (int i = 0;i < len; ++i) { + stack[i] = new State(); + } + return stack; + } } - private final State[] stack = new State[32]; + private final State[] stack = State.createStates(32); private final boolean debugEnabled = logger.isDebugEnabled(); @@ -290,7 +309,7 @@ public boolean decode(ByteBuf buffer, CommandOutput output, Consumer