8000 Merge pull request #149 from antonzherdev/row-data-refactoring · keevol/postgresql-async@cf705f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit cf705f8

Browse files
committed
Merge pull request mauricio#149 from antonzherdev/row-data-refactoring
Array row data refactoring. Avoiding copy data by columns.
2 parents 654a377 + 1c9b98d commit cf705f8

File tree

3 files changed

+5
-26
lines changed

3 files changed

+5
-26
lines changed

db-async-common/src/main/scala/com/github/mauricio/async/db/general/ArrayRowData.scala

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,10 @@
1717
package com.github.mauricio.async.db.general
1818

1919
import com.github.mauricio.async.db.RowData
20-
import scala.collection.mutable
2120

22-
class ArrayRowData( columnCount : Int, row : Int, val mapping : Map[String, Int] )
23-
extends RowData
21+
class ArrayRowData(row : Int, val mapping : Map[String, Int], val columns : Array[Any]) extends RowData
2422
{
2523

26-
private val columns = new Array[Any](columnCount)
27-
2824
/**
2925
*
3026
* Returns a column value by it's position in the originating query.
@@ -51,16 +47,5 @@ class ArrayRowData( columnCount : Int, row : Int, val mapping : Map[String, Int]
5147
*/
5248
def rowNumber: Int = row
5349

54-
/**
55-
*
56-
* Sets a value to a column in this collection.
57-
*
58-
* @param i
59-
* @param x
60-
*/
61-
62-
def update(i: Int, x: Any) = columns(i) = x
63-
6450
def length: Int = columns.length
65-
6651
}

db-async-common/src/main/scala/com/github/mauricio/async/db/general/MutableResultSet.scala

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,8 @@ class MutableResultSet[T <: ColumnData](
3939

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

42-
def addRow( row : Seq[Any] ) {
43-
val realRow = new ArrayRowData( columnTypes.size, this.rows.size, this.columnMapping )
44-
var x = 0
45-
while ( x < row.size ) {
46-
realRow(x) = row(x)
47-
x += 1
48-
}
49-
this.rows += realRow
42+
def addRow(row : Array[Any] ) {
43+
this.rows += new ArrayRowData(this.rows.size, this.columnMapping, row)
5044
}
5145

5246
}

mysql-async/src/main/scala/com/github/mauricio/async/db/mysql/binary/BinaryRowDecoder.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class BinaryRowDecoder {
3131

3232
//import BinaryRowDecoder._
3333

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

3636
//log.debug("columns are {} - {}", buffer.readableBytes(), columns)
3737
//log.debug( "decoding row\n{}", MySQLHelper.dumpAsHex(buffer))
@@ -79,7 +79,7 @@ class BinaryRowDecoder {
7979
throw new BufferNotFullyConsumedException(buffer)
8080
}
8181

82-
row
82+
row.toArray
8383
}
8484

8585
}

0 commit comments

Comments
 (0)
0