Skip to content

Commit

Permalink
feat: 🎸 remove extra check at read
Browse files Browse the repository at this point in the history
  • Loading branch information
streamich committed Aug 11, 2024
1 parent 123ce39 commit 3a08a95
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/LruMap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ export class LruMap<K, V> extends Map<K, V> {
}

public set(key: K, value: V): this {
super.delete(key);
super.set(key, value);
if (this.size > this.limit) this.delete(super.keys().next().value!);
return this;
}

public get(key: K): V | undefined {
if (!super.has(key)) return undefined;
const value = super.get(key)!;
if (value === void 0) return;
super.delete(key);
super.set(key, value);
return value;
Expand Down

0 comments on commit 3a08a95

Please sign in to comment.