Cache result parser lookups

This commit is contained in:
Brian Carlson 2013-07-08 09:32:53 -05:00
parent 413eff72e5
commit 5462561e51

View File

@ -9,6 +9,7 @@ var Result = function() {
this.oid = null;
this.rows = [];
this.fields = [];
this._parsers = [];
};
var matchRegexp = /([A-Za-z]+) ?(\d+ )?(\d+)?/;
@ -46,7 +47,7 @@ Result.prototype.parseRow = function(rowData) {
var fieldType = field.dataTypeID;
var parsedValue = null;
if(rawValue !== null) {
parsedValue = types.getTypeParser(fieldType, field.format || 'text')(rawValue);
parsedValue = this._parsers[i](rawValue);
}
var fieldName = field.name;
row[fieldName] = parsedValue;
@ -65,9 +66,12 @@ Result.prototype.addFields = function(fieldDescriptions) {
//you need to reset the fields
if(this.fields.length) {
this.fields = [];
this._parsers = [];
}
for(var i = 0; i < fieldDescriptions.length; i++) {
this.fields.push(fieldDescriptions[i]);
var desc = fieldDescriptions[i];
this.fields.push(desc);
this._parsers.push(types.getTypeParser(desc.dataTypeID, desc.format || 'text'));
}
};