Skip to content

Commit

Permalink
Swapping null for '' as an interim fix for an erroneous null va…
Browse files Browse the repository at this point in the history
…lue which collides with `remove()` - lack of time / this'll solve it for now; no negative impact on `bench-lru` results
  • Loading branch information
avoidwork committed Mar 25, 2018
1 parent 8708506 commit df0a745
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 45 deletions.
25 changes: 13 additions & 12 deletions lib/tiny-lru.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
* @copyright 2018
* @license BSD-3-Clause
* @link https://github.com/avoidwork/tiny-lru
* @version 1.5.0
* @version 1.5.1
*/
"use strict";

(function (global) {
const next = typeof process !== "undefined" ? process.nextTick : arg => setTimeout(arg, 1);
const next = typeof process !== "undefined" ? process.nextTick : arg => setTimeout(arg, 1),
empty = "";

class LRU {
constructor (max, notify, ttl) {
Expand Down Expand Up @@ -108,7 +109,7 @@
this.first = cached.previous;
}
} else if (this.first === key) {
this.first = null;
this.first = empty;
}

if (this.has(cached.next)) {
Expand All @@ -118,15 +119,15 @@
this.last = cached.next;
}
} else if (this.last === key) {
this.last = null;
this.last = empty;
}
} else {
if (this.first === key) {
this.first = null;
this.first = empty;
}

if (this.last === key) {
this.last = null;
this.last = empty;
}
}

Expand All @@ -143,8 +144,8 @@
}

this.cache = {};
this.first = null;
this.last = null;
this.first = empty;
this.last = empty;
this.length = 0;
this.timers = {};

Expand All @@ -157,13 +158,13 @@
if (this.has(key)) {
item = this.cache[key];
item.value = value;
item.next = null;
item.next = empty;

if (this.first !== key) {
item.previous = this.first;
}

if (this.last === key && item.previous !== null) {
if (this.last === key && item.previous !== empty) {
this.last = item.previous;
}
} else {
Expand All @@ -176,7 +177,7 @@
}

this.cache[key] = {
next: null,
next: empty,
previous: this.first,
value: value
};
Expand All @@ -187,7 +188,7 @@
first.next = key;

if (first.previous === key) {
first.previous = null;
first.previous = empty;
}
}

Expand Down
25 changes: 13 additions & 12 deletions lib/tiny-lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @copyright 2018
* @license BSD-3-Clause
* @link https://github.com/avoidwork/tiny-lru
* @version 1.5.0
* @version 1.5.1
*/
"use strict";

Expand All @@ -16,7 +16,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
(function (global) {
var next = typeof process !== "undefined" ? process.nextTick : function (arg) {
return setTimeout(arg, 1);
};
},
empty = "";

var LRU = function () {
function LRU(max, notify, ttl) {
Expand Down Expand Up @@ -134,7 +135,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
this.first = cached.previous;
}
} else if (this.first === key) {
this.first = null;
this.first = empty;
}

if (this.has(cached.next)) {
Expand All @@ -144,15 +145,15 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
this.last = cached.next;
}
} else if (this.last === key) {
this.last = null;
this.last = empty;
}
} else {
if (this.first === key) {
this.first = null;
this.first = empty;
}

if (this.last === key) {
this.last = null;
this.last = empty;
}
}

Expand All @@ -174,8 +175,8 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}

this.cache = {};
this.first = null;
this.last = null;
this.first = empty;
this.last = empty;
this.length = 0;
this.timers = {};

Expand All @@ -190,13 +191,13 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
if (this.has(key)) {
item = this.cache[key];
item.value = value;
item.next = null;
item.next = empty;

if (this.first !== key) {
item.previous = this.first;
}

if (this.last === key && item.previous !== null) {
if (this.last === key && item.previous !== empty) {
this.last = item.previous;
}
} else {
Expand All @@ -209,7 +210,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
}

this.cache[key] = {
next: null,
next: empty,
previous: this.first,
value: value
};
Expand All @@ -220,7 +221,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons
first.next = key;

if (first.previous === key) {
first.previous = null;
first.previous = empty;
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/tiny-lru.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit df0a745

Please sign in to comment.