From 5462561e514ce56168c5527ccd8a881231855f33 Mon Sep 17 00:00:00 2001 From: Brian Carlson Date: Mon, 8 Jul 2013 09:32:53 -0500 Subject: [PATCH] Cache result parser lookups --- lib/result.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/result.js b/lib/result.js index 7a953b2..d638305 100644 --- a/lib/result.js +++ b/lib/result.js @@ -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')); } };