Comparing version 5.0.2 to 5.0.3
@@ -45,3 +45,3 @@ /*jslint node: true */ | ||
bench: { | ||
cmd: './node_modules/.bin/bench -c 20000 -i bench/options/default.js,bench/options/dedup.js,bench/options/mapval.js,bench/options/default-native.js,bench/options/dedup-native.js -k options bench/add bench/add_match_remove bench/match bench/match_search bench/test' | ||
cmd: './node_modules/.bin/bench -c 20000 -i bench/options/default.js,bench/options/dedup.js,bench/options/mapval.js,bench/options/default-native.js,bench/options/dedup-native.js,bench/options/default-cache-splits.js -k options bench/add bench/add_match_remove bench/match bench/match_search bench/test' | ||
}, | ||
@@ -54,3 +54,3 @@ | ||
'bench-many': { | ||
cmd: './node_modules/.bin/bench -c 1 -i bench/options/default.js,bench/options/dedup.js,bench/options/mapval.js,bench/options/default-native.js,bench/options/dedup-native.js -k options bench/add_many bench/add_shortcut_many bench/match_many bench/match_search_many bench/test_many' | ||
cmd: './node_modules/.bin/bench -c 1 -i bench/options/default.js,bench/options/dedup.js,bench/options/mapval.js,bench/options/default-native.js,bench/options/dedup-native.js,bench/options/default-cache-splits.js -k options bench/add_many bench/add_shortcut_many bench/match_many bench/match_search_many bench/test_many' | ||
} | ||
@@ -57,0 +57,0 @@ } |
@@ -222,2 +222,4 @@ /** | ||
- `{Integer} cache_splits` How many `topic.split` results to cache. When you pass in a topic, it has to be split on the `separator`. Caching the results will make using the same topics multiple times faster at the cost of extra memory usage. Defaults to `0` (no caching). The number of split results cached is limited by the value you pass here. | ||
- `{Integer} max_words` Maximum number of words to allow in a topic. Defaults to 100. | ||
@@ -246,2 +248,7 @@ | ||
} | ||
if (options.cache_splits > 0) | ||
{ | ||
this._cache_splits = options.cache_splits; | ||
this._split_cache = new Map(); | ||
} | ||
} | ||
@@ -595,3 +602,3 @@ | ||
Qlobber.prototype._split = function (topic, adding) { | ||
Qlobber.prototype._split_words = function (topic) { | ||
const r = topic.split(this._separator); | ||
@@ -601,2 +608,22 @@ if (r.length > this._max_words) { | ||
} | ||
return r; | ||
}; | ||
Qlobber.prototype._split = function (topic, adding) { | ||
let r; | ||
if (this._split_cache) { | ||
r = this._split_cache.get(topic); | ||
if (r === undefined) { | ||
r = this._split_words(topic); | ||
this._split_cache.set(topic, r); | ||
if (this._split_cache.size > this._cache_splits) { | ||
for (let t of this._split_cache.keys()) { | ||
this._split_cache.delete(t); | ||
break; | ||
} | ||
} | ||
} | ||
} else { | ||
r = this._split_words(topic); | ||
} | ||
if (adding && | ||
@@ -711,2 +738,6 @@ (r.reduce((n, w) => n + (w === this._wildcard_some), 0) > this._max_wildcard_somes)) { | ||
} | ||
if (this._split_cache) | ||
{ | ||
this._split_cache.clear(); | ||
} | ||
return this; | ||
@@ -713,0 +744,0 @@ }; |
{ | ||
"name": "qlobber", | ||
"description": "Node.js globbing for amqp-like topics", | ||
"version": "5.0.2", | ||
"version": "5.0.3", | ||
"homepage": "https://github.com/davedoesdev/qlobber", | ||
@@ -34,3 +34,2 @@ "author": { | ||
"rabbitmq", | ||
"cybertron", | ||
"ascoltatore" | ||
@@ -37,0 +36,0 @@ ], |
@@ -241,2 +241,4 @@ # qlobber [![Build Status](https://travis-ci.org/davedoesdev/qlobber.png)](https://travis-ci.org/davedoesdev/qlobber) [![Coverage Status](https://coveralls.io/repos/davedoesdev/qlobber/badge.png?branch=master)](https://coveralls.io/r/davedoesdev/qlobber?branch=master) [![NPM version](https://badge.fury.io/js/qlobber.png)](http://badge.fury.io/js/qlobber) | ||
- `{Integer} cache_splits` How many `topic.split` results to cache. When you pass in a topic, it has to be split on the `separator`. Caching the results will make using the same topics multiple times faster at the cost of extra memory usage. Defaults to `0` (no caching). The number of split results cached is limited by the value you pass here. | ||
- `{Integer} max_words` Maximum number of words to allow in a topic. Defaults to 100. | ||
@@ -243,0 +245,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
60794
1208
517