Skip to content

Commit b6bca99

Browse files
committed
Minor speed improvements
1 parent 56b7c41 commit b6bca99

File tree

1 file changed

+32
-19
lines changed

1 file changed

+32
-19
lines changed

lib/connection.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -472,8 +472,9 @@ Connection.prototype.parseZ = function(buffer, length) {
472472
return msg;
473473
};
474474

475+
ROW_DESCRIPTION = 'rowDescription';
475476
Connection.prototype.parseT = function(buffer, length) {
476-
var msg = new Message('rowDescription', length);
477+
var msg = new Message(ROW_DESCRIPTION, length);
477478
msg.fieldCount = this.parseInt16(buffer);
478479
var fields = [];
479480
for(var i = 0; i < msg.fieldCount; i++){
@@ -483,44 +484,56 @@ Connection.prototype.parseT = function(buffer, length) {
483484
return msg;
484485
};
485486

487+
var Field = function() {
488+
this.name = null;
489+
this.tableID = null;
490+
this.columnID = null;
491+
this.dataTypeID = null;
492+
this.dataTypeSize = null;
493+
this.dataTypeModifier = null;
494+
this.format = null;
495+
};
496+
497+
FORMAT_TEXT = 'text';
498+
FORMAT_BINARY = 'binary';
486499
Connection.prototype.parseField = function(buffer) {
487-
var field = {
488-
name: this.parseCString(buffer),
489-
tableID: this.parseInt32(buffer),
490-
columnID: this.parseInt16(buffer),
491-
dataTypeID: this.parseInt32(buffer),
492-
dataTypeSize: this.parseInt16(buffer),
493-
dataTypeModifier: this.parseInt32(buffer),
494-
format: undefined
495-
};
500+
var field = new Field();
501+
field.name = this.parseCString(buffer);
502+
field.tableID = this.parseInt32(buffer);
503+
field.columnID = this.parseInt16(buffer);
504+
field.dataTypeID = this.parseInt32(buffer);
505+
field.dataTypeSize = this.parseInt16(buffer);
506+
field.dataTypeModifier = this.parseInt32(buffer);
496507
if(this.parseInt16(buffer) === TEXT_MODE) {
497508
this._mode = TEXT_MODE;
498-
field.format = 'text';
509+
field.format = FORMAT_TEXT;
499510
} else {
500511
this._mode = BINARY_MODE;
501-
this.readField = this.readBytes;
502-
field.format = 'binary';
512+
field.format = FORMAT_BINARY;
503513
}
504514
return field;
505515
};
506516

517+
DATA_ROW = 'dataRow';
507518
var DataRowMessage = function(name, length, fieldCount) {
508-
this.name = name;
519+
this.name = DATA_ROW;
509520
this.length = length;
510521
this.fieldCount = fieldCount;
511522
this.fields = [];
512-
}
523+
};
524+
513525

514-
Connection.prototype.parseD = function(buffer, length) {
526+
//extremely hot-path code
527+
Connection.prototype[0x44] = Connection.prototype.parseD = function(buffer, length) {
515528
var fieldCount = this.parseInt16(buffer);
516-
var msg = new DataRowMessage('dataRow', length, fieldCount);
529+
var msg = new DataRowMessage(length, fieldCount);
517530
for(var i = 0; i < fieldCount; i++) {
518-
var value = this._readValue(buffer);
519-
msg.fields.push(value);
531+
msg.fields.push(this._readValue(buffer));
520532
}
521533
return msg;
522534
};
523535

536+
//extremely hot-path code
524537
Connection.prototype._readValue = function(buffer) {
525538
var length = this.parseInt32(buffer);
526539
if(length === -1) return null;

0 commit comments

Comments
 (0)