mirror of
https://github.com/brianc/node-postgres.git
synced 2025-12-08 20:16:25 +00:00
Minor speed improvements
This commit is contained in:
parent
56b7c4168d
commit
b6bca99489
@ -472,8 +472,9 @@ Connection.prototype.parseZ = function(buffer, length) {
|
||||
return msg;
|
||||
};
|
||||
|
||||
ROW_DESCRIPTION = 'rowDescription';
|
||||
Connection.prototype.parseT = function(buffer, length) {
|
||||
var msg = new Message('rowDescription', length);
|
||||
var msg = new Message(ROW_DESCRIPTION, length);
|
||||
msg.fieldCount = this.parseInt16(buffer);
|
||||
var fields = [];
|
||||
for(var i = 0; i < msg.fieldCount; i++){
|
||||
@ -483,44 +484,56 @@ Connection.prototype.parseT = function(buffer, length) {
|
||||
return msg;
|
||||
};
|
||||
|
||||
var Field = function() {
|
||||
this.name = null;
|
||||
this.tableID = null;
|
||||
this.columnID = null;
|
||||
this.dataTypeID = null;
|
||||
this.dataTypeSize = null;
|
||||
this.dataTypeModifier = null;
|
||||
this.format = null;
|
||||
};
|
||||
|
||||
FORMAT_TEXT = 'text';
|
||||
FORMAT_BINARY = 'binary';
|
||||
Connection.prototype.parseField = function(buffer) {
|
||||
var field = {
|
||||
name: this.parseCString(buffer),
|
||||
tableID: this.parseInt32(buffer),
|
||||
columnID: this.parseInt16(buffer),
|
||||
dataTypeID: this.parseInt32(buffer),
|
||||
dataTypeSize: this.parseInt16(buffer),
|
||||
dataTypeModifier: this.parseInt32(buffer),
|
||||
format: undefined
|
||||
};
|
||||
var field = new Field();
|
||||
field.name = this.parseCString(buffer);
|
||||
field.tableID = this.parseInt32(buffer);
|
||||
field.columnID = this.parseInt16(buffer);
|
||||
field.dataTypeID = this.parseInt32(buffer);
|
||||
field.dataTypeSize = this.parseInt16(buffer);
|
||||
field.dataTypeModifier = this.parseInt32(buffer);
|
||||
if(this.parseInt16(buffer) === TEXT_MODE) {
|
||||
this._mode = TEXT_MODE;
|
||||
field.format = 'text';
|
||||
field.format = FORMAT_TEXT;
|
||||
} else {
|
||||
this._mode = BINARY_MODE;
|
||||
this.readField = this.readBytes;
|
||||
field.format = 'binary';
|
||||
field.format = FORMAT_BINARY;
|
||||
}
|
||||
return field;
|
||||
};
|
||||
|
||||
DATA_ROW = 'dataRow';
|
||||
var DataRowMessage = function(name, length, fieldCount) {
|
||||
this.name = name;
|
||||
this.name = DATA_ROW;
|
||||
this.length = length;
|
||||
this.fieldCount = fieldCount;
|
||||
this.fields = [];
|
||||
}
|
||||
};
|
||||
|
||||
Connection.prototype.parseD = function(buffer, length) {
|
||||
|
||||
//extremely hot-path code
|
||||
Connection.prototype[0x44] = Connection.prototype.parseD = function(buffer, length) {
|
||||
var fieldCount = this.parseInt16(buffer);
|
||||
var msg = new DataRowMessage('dataRow', length, fieldCount);
|
||||
var msg = new DataRowMessage(length, fieldCount);
|
||||
for(var i = 0; i < fieldCount; i++) {
|
||||
var value = this._readValue(buffer);
|
||||
msg.fields.push(value);
|
||||
msg.fields.push(this._readValue(buffer));
|
||||
}
|
||||
return msg;
|
||||
};
|
||||
|
||||
//extremely hot-path code
|
||||
Connection.prototype._readValue = function(buffer) {
|
||||
var length = this.parseInt32(buffer);
|
||||
if(length === -1) return null;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user