-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf(cancellations): use an Array instead of a linked list
Arrays have lower memory usage
- Loading branch information
1 parent
0aa708f
commit 782cf80
Showing
3 changed files
with
22 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,37 @@ | ||
/** | ||
* Created by tushar on 2019-05-14 | ||
*/ | ||
import {LinkedList, LinkedListNode} from 'dbl-linked-list-ds' | ||
|
||
import {ICancellable} from 'ts-scheduler' | ||
|
||
/** | ||
* @ignore | ||
*/ | ||
export type CancelId = number | ||
|
||
/** | ||
* Collection of cancellables | ||
* @ignore | ||
*/ | ||
export class CancellationList { | ||
private readonly q = new LinkedList<ICancellable>() | ||
private readonly q = new Array<ICancellable>() | ||
|
||
public cancel(): void { | ||
let node = this.q.shift() | ||
let node = this.q.pop() | ||
while (node !== undefined) { | ||
node.cancel() | ||
node = this.q.shift() | ||
node = this.q.pop() | ||
} | ||
} | ||
|
||
public cancelId(node: LinkedListNode<ICancellable>): void { | ||
node.value.cancel() | ||
this.q.remove(node) | ||
public cancelId(id: CancelId): void { | ||
const node = this.q[id] | ||
node.cancel() | ||
|
||
this.q[id] = this.q[this.q.length - 1] | ||
this.q.pop() | ||
} | ||
|
||
public push(cancel: ICancellable): LinkedListNode<ICancellable> { | ||
return this.q.add(cancel) | ||
public push(cancel: ICancellable): CancelId { | ||
return this.q.push(cancel) - 1 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters