Skip to content

Commit

Permalink
finagle-mysql: Moved Request Components from vals to defs
Browse files Browse the repository at this point in the history
Problem / Solution

Finagle-Mysql's `Request` trait contains `seq` and `cmd` definitions
which are marked as vals, however using a val is unnecessary. Let's
change them to defs to lower the footprint of the classes based on
`Request`.

JIRA Issues: CSL-7996

Differential Revision: https://phabricator.twitter.biz/D303766
  • Loading branch information
ryanoneill authored and jenkins committed Apr 22, 2019
1 parent 170c2d6 commit d2e2562
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ object Command {
}

sealed trait Request {
val seq: Short
val cmd: Byte = Command.COM_NO_OP
def seq: Short
def cmd: Byte = Command.COM_NO_OP
def toPacket: Packet
}

Expand All @@ -53,8 +53,8 @@ sealed trait WithSql {
}

private[finagle] object PoisonConnectionRequest extends Request {
val seq: Short = 0
override val cmd: Byte = Command.COM_POISON_CONN
def seq: Short = 0
override def cmd: Byte = Command.COM_POISON_CONN
def toPacket: Packet = ???
}

Expand All @@ -63,7 +63,7 @@ private[finagle] object PoisonConnectionRequest extends Request {
* and has a cmd byte associated with it.
*/
abstract class CommandRequest(override val cmd: Byte) extends Request {
val seq: Short = 0
def seq: Short = 0
}

/**
Expand Down Expand Up @@ -134,7 +134,7 @@ private[mysql] case class SslConnectionRequest(
clientCap.has(Capability.SSL),
"Using SslConnectionRequest requires having the SSL capability")

override val seq: Short = 1
override def seq: Short = 1

def toPacket: Packet = {
val packetBodySize = 32
Expand Down Expand Up @@ -164,7 +164,8 @@ case class HandshakeResponse(
charset: Short,
maxPacketSize: Int)
extends Request {
override val seq: Short = 1

def seq: Short = 1

lazy val hashPassword: Array[Byte] = password match {
case Some(p) => encryptPassword(p, salt)
Expand Down Expand Up @@ -208,6 +209,7 @@ case class HandshakeResponse(

class FetchRequest(val prepareOK: PrepareOK, val numRows: Int)
extends CommandRequest(Command.COM_STMT_FETCH) {

val stmtId: Int = prepareOK.id

def toPacket: Packet = {
Expand All @@ -231,6 +233,7 @@ class ExecuteRequest(
val hasNewParams: Boolean,
val flags: Byte)
extends CommandRequest(Command.COM_STMT_EXECUTE) {

private[this] val log = Logger.getLogger("finagle-mysql")

private[this] def makeNullBitmap(parameters: IndexedSeq[Parameter]): Array[Byte] = {
Expand Down

0 comments on commit d2e2562

Please sign in to comment.