Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion benchmarks/comparison-benchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ try {
try {
// Import from mnemonist using the correct export pattern
const mnemonistModule = await import("mnemonist");
MnemonistLRU = mnemonistModule.LRUCache;
MnemonistLRU = mnemonistModule.LRUCacheWithDelete;
} catch (error) {
console.error("mnemonist not found. Run: npm install --no-save mnemonist");
console.error("Error:", error.message);
Expand Down
20 changes: 16 additions & 4 deletions src/lru.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ export class LRU {
* @since 11.1.0
*/
entries (keys = this.keys()) {
return keys.map(key => [key, this.get(key)]);
const result = new Array(keys.length);
for (let i = 0; i < keys.length; i++) {
const key = keys[i];
result[i] = [key, this.get(key)];
}

return result;
}

/**
Expand Down Expand Up @@ -296,11 +302,12 @@ export class LRU {
* @since 9.0.0
*/
keys () {
const result = [];
const result = new Array(this.size);
let x = this.first;
let i = 0;

while (x !== null) {
result.push(x.key);
result[i++] = x.key;
x = x.next;
}

Expand Down Expand Up @@ -429,7 +436,12 @@ export class LRU {
* @since 11.1.0
*/
values (keys = this.keys()) {
return keys.map(key => this.get(key));
const result = new Array(keys.length);
for (let i = 0; i < keys.length; i++) {
result[i] = this.get(keys[i]);
}

return result;
}
}

Expand Down
Loading