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