Permalink
Browse files

Comments for XRegExp.cache

  • Loading branch information...
1 parent 8c411fb commit 299da97533eca65f6153425fc1c70376866967c4 @slevithan committed Aug 20, 2012
Showing with 6 additions and 4 deletions.
  1. +3 −2 src/xregexp.js
  2. +3 −2 xregexp-all.js
View
@@ -566,7 +566,7 @@ var XRegExp = (function(undefined) {
/**
* 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
* @param {String} pattern Regex pattern string.
* @param {String} [flags] Any combination of XRegExp flags.
@@ -578,16 +578,17 @@ var XRegExp = (function(undefined) {
* }
*/
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 || '');
return cache[key] || (cache[key] = self(pattern, flags));
};
// Intentionally undocumented
self.cache.flush = function(cacheName) {
if (cacheName === 'patterns') {
+ // Flush the pattern cache used by the `XRegExp` constructor
patternCache = {};
} else {
+ // Flush the regex object cache populated by `XRegExp.cache`
cache = {};
}
};
View
@@ -593,7 +593,7 @@ var XRegExp = (function(undefined) {
/**
* 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
* @param {String} pattern Regex pattern string.
* @param {String} [flags] Any combination of XRegExp flags.
@@ -605,16 +605,17 @@ var XRegExp = (function(undefined) {
* }
*/
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 || '');
return cache[key] || (cache[key] = self(pattern, flags));
};
// Intentionally undocumented
self.cache.flush = function(cacheName) {
if (cacheName === 'patterns') {
+ // Flush the pattern cache used by the `XRegExp` constructor
patternCache = {};
} else {
+ // Flush the regex object cache populated by `XRegExp.cache`
cache = {};
}
};

0 comments on commit 299da97

Please sign in to comment.