From e3fe0ae3522ed3673d8182c80b421579bfe2f44a Mon Sep 17 00:00:00 2001 From: Ben Cherry Date: Wed, 13 Jul 2011 15:04:44 -0700 Subject: [PATCH] fix a bug in regex generators, make cache global --- mustache.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/mustache.js b/mustache.js index 83184df..1c0f029 100644 --- a/mustache.js +++ b/mustache.js @@ -5,6 +5,7 @@ */ var Mustache = function() { + var regexCache = {}; var Renderer = function() {}; Renderer.prototype = { @@ -355,13 +356,9 @@ var Mustache = function() { }, getCachedRegex: function(name, generator) { - if (!this._regexCache) { - this._regexCache = {}; - } - - var byOtag = this._regexCache[this.otag]; + var byOtag = regexCache[this.otag]; if (!byOtag) { - byOtag = this._regexCache[this.otag] = {}; + byOtag = regexCache[this.otag] = {}; } var byCtag = byOtag[this.ctag]; @@ -371,7 +368,7 @@ var Mustache = function() { var regex = byCtag[name]; if (!regex) { - regex = byCtag[name] = generator(this.ctag, this.otag); + regex = byCtag[name] = generator(this.otag, this.ctag); } return regex;