Skip to content

Commit 5462561

Browse files
committed
Cache result parser lookups
1 parent 413eff7 commit 5462561

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

lib/result.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ var Result = function() {
99
this.oid = null;
1010
this.rows = [];
1111
this.fields = [];
12+
this._parsers = [];
1213
};
1314

1415
var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/;
@@ -46,7 +47,7 @@ Result.prototype.parseRow = function(rowData) {
4647
var fieldType = field.dataTypeID;
4748
var parsedValue = null;
4849
if(rawValue !== null) {
49-
parsedValue = types.getTypeParser(fieldType, field.format || 'text')(rawValue);
50+
parsedValue = this._parsers[i](rawValue);
5051
}
5152
var fieldName = field.name;
5253
row[fieldName] = parsedValue;
@@ -65,9 +66,12 @@ Result.prototype.addFields = function(fieldDescriptions) {
6566
//you need to reset the fields
6667
if(this.fields.length) {
6768
this.fields = [];
69+
this._parsers = [];
6870
}
6971
for(var i = 0; i < fieldDescriptions.length; i++) {
70-
this.fields.push(fieldDescriptions[i]);
72+
var desc = fieldDescriptions[i];
73+
this.fields.push(desc);
74+
this._parsers.push(types.getTypeParser(desc.dataTypeID, desc.format || 'text'));
7175
}
7276
};
7377

0 commit comments

Comments
 (0)