Skip to content

Commit 53b8e3b

Browse files
committed
clean up connection slightly & add initial bench
1 parent e020cfa commit 53b8e3b

File tree

2 files changed

+32
-25
lines changed

2 files changed

+32
-25
lines changed

benchmark/835f71a76f.txt

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
benchmark
2+
starting simple-query-parsing
3+
3703 ops/sec - (100/0.027)
4+
7299 ops/sec - (1000/0.137)
5+
8888 ops/sec - (10000/1.125)
6+
8733 ops/sec - (10000/1.145)
7+
8810 ops/sec - (10000/1.135)
8+
8771 ops/sec - (10000/1.14)
9+
starting prepared-statement-parsing
10+
3846 ops/sec - (100/0.026)
11+
7299 ops/sec - (1000/0.137)
12+
7225 ops/sec - (10000/1.384)
13+
7288 ops/sec - (10000/1.372)
14+
7225 ops/sec - (10000/1.384)
15+
7457 ops/sec - (10000/1.341)
16+
done
17+

lib/connection.js

Lines changed: 15 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ Connection.prototype.parseT = function(msg) {
477477
msg.fieldCount = this.parseInt16();
478478
var fields = [];
479479
for(var i = 0; i < msg.fieldCount; i++){
480-
fields[i] = this.parseField();
480+
fields.push(this.parseField());
481481
}
482482
msg.fields = fields;
483483
return msg;
@@ -501,7 +501,11 @@ Connection.prototype.parseD = function(msg) {
501501
var fields = [];
502502
for(var i = 0; i < fieldCount; i++) {
503503
var length = this.parseInt32();
504-
fields[i] = (length === -1 ? null : this.readBytes(length));
504+
var value = null;
505+
if(length !== -1) {
506+
value = this.readBytes(length);
507+
}
508+
fields.push(value);
505509
}
506510
msg.fieldCount = fieldCount;
507511
msg.fields = fields;
@@ -556,49 +560,35 @@ Connection.prototype.parseA = function(msg) {
556560
};
557561

558562
Connection.prototype.parseGH = function (msg) {
559-
msg.binary = Boolean(this.parseInt8());
563+
var isBinary = this.buffer[this.offset] !== 0;
564+
this.offset++;
565+
msg.binary = isBinary;
560566
var columnCount = this.parseInt16();
561567
msg.columnTypes = [];
562568
for(var i = 0; i<columnCount; i++) {
563-
msg.columnTypes[i] = this.parseInt16();
569+
msg.columnTypes.push(this.parseInt16());
564570
}
565571
return msg;
566572
};
567573

568-
Connection.prototype.parseInt8 = function () {
569-
var value = Number(this.buffer[this.offset]);
570-
this.offset++;
571-
return value;
572-
};
573-
574574
Connection.prototype.readChar = function() {
575575
return Buffer([this.buffer[this.offset++]]).toString(this.encoding);
576576
};
577577

578578
Connection.prototype.parseInt32 = function() {
579-
var value = this.peekInt32();
579+
var value = this.buffer.readInt32BE(this.offset, true);
580580
this.offset += 4;
581581
return value;
582582
};
583583

584-
Connection.prototype.peekInt32 = function(offset) {
585-
offset = offset || this.offset;
586-
var buffer = this.buffer;
587-
return ((buffer[offset++] << 24) +
588-
(buffer[offset++] << 16) +
589-
(buffer[offset++] << 8) +
590-
buffer[offset++]);
591-
};
592-
593-
594584
Connection.prototype.parseInt16 = function() {
595-
return ((this.buffer[this.offset++] << 8) +
596-
(this.buffer[this.offset++] << 0));
585+
var value = this.buffer.readInt16BE(this.offset, true);
586+
this.offset += 2;
587+
return value;
597588
};
598589

599590
Connection.prototype.readString = function(length) {
600-
return this.buffer.toString(this.encoding, this.offset,
601-
(this.offset += length));
591+
return this.buffer.toString(this.encoding, this.offset, (this.offset += length));
602592
};
603593

604594
Connection.prototype.readBytes = function(length) {

0 commit comments

Comments
 (0)