Skip to content

Commit

Permalink
Comments for XRegExp.cache
Browse files Browse the repository at this point in the history
  • Loading branch information
slevithan committed Aug 20, 2012
1 parent 8c411fb commit 299da97
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/xregexp.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -566,7 +566,7 @@ var XRegExp = (function(undefined) {


/** /**
* Caches and returns the result of calling `XRegExp(pattern, flags)`. On any subsequent call with * Caches and returns the result of calling `XRegExp(pattern, flags)`. On any subsequent call with
* the same pattern and flag combination, the cached copy is returned. * the same pattern and flag combination, the cached copy of the regex is returned.
* @memberOf XRegExp * @memberOf XRegExp
* @param {String} pattern Regex pattern string. * @param {String} pattern Regex pattern string.
* @param {String} [flags] Any combination of XRegExp flags. * @param {String} [flags] Any combination of XRegExp flags.
Expand All @@ -578,16 +578,17 @@ var XRegExp = (function(undefined) {
* } * }
*/ */
self.cache = function(pattern, flags) { self.cache = function(pattern, flags) {
// The regex object cache is never auto-flushed, even if the user adds new syntax tokens
var key = pattern + '/' + (flags || ''); var key = pattern + '/' + (flags || '');
return cache[key] || (cache[key] = self(pattern, flags)); return cache[key] || (cache[key] = self(pattern, flags));
}; };


// Intentionally undocumented // Intentionally undocumented
self.cache.flush = function(cacheName) { self.cache.flush = function(cacheName) {
if (cacheName === 'patterns') { if (cacheName === 'patterns') {
// Flush the pattern cache used by the `XRegExp` constructor
patternCache = {}; patternCache = {};
} else { } else {
// Flush the regex object cache populated by `XRegExp.cache`
cache = {}; cache = {};
} }
}; };
Expand Down
5 changes: 3 additions & 2 deletions xregexp-all.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -593,7 +593,7 @@ var XRegExp = (function(undefined) {


/** /**
* Caches and returns the result of calling `XRegExp(pattern, flags)`. On any subsequent call with * Caches and returns the result of calling `XRegExp(pattern, flags)`. On any subsequent call with
* the same pattern and flag combination, the cached copy is returned. * the same pattern and flag combination, the cached copy of the regex is returned.
* @memberOf XRegExp * @memberOf XRegExp
* @param {String} pattern Regex pattern string. * @param {String} pattern Regex pattern string.
* @param {String} [flags] Any combination of XRegExp flags. * @param {String} [flags] Any combination of XRegExp flags.
Expand All @@ -605,16 +605,17 @@ var XRegExp = (function(undefined) {
* } * }
*/ */
self.cache = function(pattern, flags) { self.cache = function(pattern, flags) {
// The regex object cache is never auto-flushed, even if the user adds new syntax tokens
var key = pattern + '/' + (flags || ''); var key = pattern + '/' + (flags || '');
return cache[key] || (cache[key] = self(pattern, flags)); return cache[key] || (cache[key] = self(pattern, flags));
}; };


// Intentionally undocumented // Intentionally undocumented
self.cache.flush = function(cacheName) { self.cache.flush = function(cacheName) {
if (cacheName === 'patterns') { if (cacheName === 'patterns') {
// Flush the pattern cache used by the `XRegExp` constructor
patternCache = {}; patternCache = {};
} else { } else {
// Flush the regex object cache populated by `XRegExp.cache`
cache = {}; cache = {};
} }
}; };
Expand Down

0 comments on commit 299da97

Please sign in to comment.