From 84a87d423c2747076cde4113499c8aac09175275 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Mon, 12 Sep 2011 15:18:13 -0400 Subject: [PATCH] performance tweak --- jasmine/jasmine.headless-reporter.coffee | 21 +++++++++++++++------ jasmine/jasmine.headless-reporter.js | 23 +++++++++++++++-------- 2 files changed, 30 insertions(+), 14 deletions(-) diff --git a/jasmine/jasmine.headless-reporter.coffee b/jasmine/jasmine.headless-reporter.coffee index edd8deb..dde6bd6 100644 --- a/jasmine/jasmine.headless-reporter.coffee +++ b/jasmine/jasmine.headless-reporter.coffee @@ -33,6 +33,7 @@ jasmine.Spec.prototype.fail = (e) -> message: e.message, lineNumber: "~" + String(e.line), sourceURL: realFilename + } expectationResult = new jasmine.ExpectationResult({ passed: false, @@ -56,18 +57,26 @@ if !jasmine.WaitsBlock.prototype._execute jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult + jasmine.NestedResults.ParsedFunctions = [] + jasmine.NestedResults.prototype.addResult = (result) -> result.expectations = [] # always three up? lineCount = 0 - for line in arguments.callee.caller.caller.caller.toString().split("\n") - line = line.replace(/^\s*/, '').replace(/\s*$/, '') - if line.match(/^\s*expect/) - result.expectations.push(line) - lineCount += 1 + + functionSignature = arguments.callee.caller.caller.caller.toString() + if !jasmine.NestedResults.ParsedFunctions[functionSignature] + lines = [] + for line in functionSignature.split("\n") + if line.match(/^\s*expect/) + line = line.replace(/^\s*/, '').replace(/\s*$/, '') + lines.push(line) + lineCount += 1 + jasmine.NestedResults.ParsedFunctions[functionSignature] = lines + result.expectations = jasmine.NestedResults.ParsedFunctions[functionSignature] this.addResult_(result) - } + jasmine.ExpectationResult.prototype.line = -> if @expectations && @lineNumber then @expectations[@lineNumber] else '' diff --git a/jasmine/jasmine.headless-reporter.js b/jasmine/jasmine.headless-reporter.js index 8904609..e6fd67f 100644 --- a/jasmine/jasmine.headless-reporter.js +++ b/jasmine/jasmine.headless-reporter.js @@ -61,19 +61,26 @@ jasmine.WaitsBlock.prototype.execute = pauseAndRun; jasmine.WaitsForBlock.prototype.execute = pauseAndRun; jasmine.NestedResults.prototype.addResult_ = jasmine.NestedResults.prototype.addResult; + jasmine.NestedResults.ParsedFunctions = []; jasmine.NestedResults.prototype.addResult = function(result) { - var line, lineCount, _i, _len, _ref; + var functionSignature, line, lineCount, lines, _i, _len, _ref; result.expectations = []; lineCount = 0; - _ref = arguments.callee.caller.caller.caller.toString().split("\n"); - for (_i = 0, _len = _ref.length; _i < _len; _i++) { - line = _ref[_i]; - line = line.replace(/^\s*/, '').replace(/\s*$/, ''); - if (line.match(/^\s*expect/)) { - result.expectations.push(line); + functionSignature = arguments.callee.caller.caller.caller.toString(); + if (!jasmine.NestedResults.ParsedFunctions[functionSignature]) { + lines = []; + _ref = functionSignature.split("\n"); + for (_i = 0, _len = _ref.length; _i < _len; _i++) { + line = _ref[_i]; + if (line.match(/^\s*expect/)) { + line = line.replace(/^\s*/, '').replace(/\s*$/, ''); + lines.push(line); + } + lineCount += 1; } - lineCount += 1; + jasmine.NestedResults.ParsedFunctions[functionSignature] = lines; } + result.expectations = jasmine.NestedResults.ParsedFunctions[functionSignature]; return this.addResult_(result); }; jasmine.ExpectationResult.prototype.line = function() {