Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

memize

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memize - npm Package Compare versions

Comparing version
1.0.4
to
1.0.5
+4
-0
CHANGELOG.md

@@ -0,1 +1,5 @@

#### v1.0.5 (2018-01-25)
- Fix: Correctly skips incorrect cached value return on mismatched argument length
#### v1.0.4 (2017-09-06)

@@ -2,0 +6,0 @@

@@ -18,3 +18,15 @@ var memize = (function () {

searchCache: while ( node ) {
// Check whether node arguments match arguments
// Perform a shallow equality test to confirm that whether the node
// under test is a candidate for the arguments passed. Two arrays
// are shallowly equal if their length matches and each entry is
// strictly equal between the two sets. Avoid abstracting to a
// function which could incur an arguments leaking deoptimization.
// Check whether node arguments match arguments length
if ( node.args.length !== arguments.length ) {
node = node.next;
continue;
}
// Check whether node arguments match arguments values
for ( i = 0; i < len; i++ ) {

@@ -21,0 +33,0 @@ if ( node.args[ i ] !== arguments[ i ] ) {

+1
-1

@@ -1,1 +0,1 @@

var memize=function(){"use strict";return function(n,r){function u(){var r,u,i=t,o=arguments.length;n:for(;i;){for(u=0;u<o;u++)if(i.n[u]!==arguments[u]){i=i.r;continue n}return i!==t&&(i===e&&(e=i.u),i.u.r=i.r,i.r&&(i.r.u=i.u),i.r=t,i.u=null,t.u=i,t=i),i.l}for(r=new Array(o),u=0;u<o;u++)r[u]=arguments[u];return i={n:r,l:n.apply(null,r)},t?(t.u=i,i.r=t):e=i,f===l?(e=e.u).r=null:f++,t=i,i.l}var l,t,e,f=0;return r&&r.t&&(l=r.t),u.clear=function(){t=null,e=null,f=0},u}}();
var memize=function(){"use strict";return function(n,r){function u(){var r,u,i=t,o=arguments.length;n:for(;i;){if(i.n.length===arguments.length){for(u=0;u<o;u++)if(i.n[u]!==arguments[u]){i=i.r;continue n}return i!==t&&(i===e&&(e=i.u),i.u.r=i.r,i.r&&(i.r.u=i.u),i.r=t,i.u=null,t.u=i,t=i),i.l}i=i.r}for(r=new Array(o),u=0;u<o;u++)r[u]=arguments[u];return i={n:r,l:n.apply(null,r)},t?(t.u=i,i.r=t):e=i,f===l?(e=e.u).r=null:f++,t=i,i.l}var l,t,e,f=0;return r&&r.t&&(l=r.t),u.clear=function(){t=null,e=null,f=0},u}}();

@@ -15,3 +15,15 @@ module.exports = function memize( fn, options ) {

searchCache: while ( node ) {
// Check whether node arguments match arguments
// Perform a shallow equality test to confirm that whether the node
// under test is a candidate for the arguments passed. Two arrays
// are shallowly equal if their length matches and each entry is
// strictly equal between the two sets. Avoid abstracting to a
// function which could incur an arguments leaking deoptimization.
// Check whether node arguments match arguments length
if ( node.args.length !== arguments.length ) {
node = node.next;
continue;
}
// Check whether node arguments match arguments values
for ( i = 0; i < len; i++ ) {

@@ -18,0 +30,0 @@ if ( node.args[ i ] !== arguments[ i ] ) {

{
"name": "memize",
"version": "1.0.4",
"version": "1.0.5",
"description": "Unabashedly-barebones memoization library with an aim toward speed",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -111,3 +111,3 @@ Memize

If you haven't already, feel free to [glance over the source code](./index.js). It's fewer than 100 lines of code of heavily commented code, and should help provide substance to the implementation concepts.
If you haven't already, feel free to [glance over the source code](./index.js). It's approximately 100 lines of code of heavily commented code, and should help provide substance to the implementation concepts.

@@ -114,0 +114,0 @@ Memize creates a [last-in first-out stack](https://en.wikipedia.org/wiki/Stack_(abstract_data_type)) implemented as a [doubly linked list](https://en.wikipedia.org/wiki/Doubly_linked_list). It biases recent access favoring real-world scenarios where the function is subsequently invoked multiple times with the same arguments. The choice to implement as a linked list is due to dramatically better performance characteristics compared to `Array#unshift` for surfacing an entry to the head of the list ([jsperf](https://jsperf.com/array-unshift-linked-list)). A downside of linked lists is inability to efficiently access arbitrary indices, but iterating from the beginning of the cache list is optimized by guaranteeing the list is sorted by recent access / insertion.