Skip to content

Commit

Permalink
Merge pull request mauricio#149 from antonzherdev/row-data-refactoring
Browse files Browse the repository at this point in the history
Array row data refactoring. Avoiding copy data by columns.
  • Loading branch information
mauricio committed Aug 10, 2015
2 parents 654a377 + 1c9b98d commit cf705f8
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,10 @@
package com.github.mauricio.async.db.general

import com.github.mauricio.async.db.RowData
import scala.collection.mutable

class ArrayRowData( columnCount : Int, row : Int, val mapping : Map[String, Int] )
extends RowData
class ArrayRowData(row : Int, val mapping : Map[String, Int], val columns : Array[Any]) extends RowData
{

private val columns = new Array[Any](columnCount)

/**
*
* Returns a column value by it's position in the originating query.
Expand All @@ -51,16 +47,5 @@ class ArrayRowData( columnCount : Int, row : Int, val mapping : Map[String, Int]
*/
def rowNumber: Int = row

/**
*
* Sets a value to a column in this collection.
*
* @param i
* @param x
*/

def update(i: Int, x: Any) = columns(i) = x

def length: Int = columns.length

}
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,8 @@ class MutableResultSet[T <: ColumnData](

override def apply(idx: Int): RowData = this.rows(idx)

def addRow( row : Seq[Any] ) {
val realRow = new ArrayRowData( columnTypes.size, this.rows.size, this.columnMapping )
var x = 0
while ( x < row.size ) {
realRow(x) = row(x)
x += 1
}
this.rows += realRow
def addRow(row : Array[Any] ) {
this.rows += new ArrayRowData(this.rows.size, this.columnMapping, row)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class BinaryRowDecoder {

//import BinaryRowDecoder._

def decode(buffer: ByteBuf, columns: Seq[ColumnDefinitionMessage]): IndexedSeq[Any] = {
def decode(buffer: ByteBuf, columns: Seq[ColumnDefinitionMessage]): Array[Any] = {

//log.debug("columns are {} - {}", buffer.readableBytes(), columns)
//log.debug( "decoding row\n{}", MySQLHelper.dumpAsHex(buffer))
Expand Down Expand Up @@ -79,7 +79,7 @@ class BinaryRowDecoder {
throw new BufferNotFullyConsumedException(buffer)
}

row
row.toArray
}

}

0 comments on commit cf705f8

Please sign in to comment.