diff options
| author | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2018-08-14 08:21:25 +0900 |
|---|---|---|
| committer | Aya Morisawa <AyaMorisawa4869@gmail.com> | 2018-08-14 08:21:25 +0900 |
| commit | bde20a1a651fca49cd2fe1806cba758602d7626c (patch) | |
| tree | b0d20d660da9f16435b9e5da4412ca21c88682e6 /src | |
| parent | Merge pull request #2199 from syuilo/patch-2176 (diff) | |
| download | sharkey-bde20a1a651fca49cd2fe1806cba758602d7626c.tar.gz sharkey-bde20a1a651fca49cd2fe1806cba758602d7626c.tar.bz2 sharkey-bde20a1a651fca49cd2fe1806cba758602d7626c.zip | |
Use deque instead of linked list
Diffstat (limited to 'src')
| -rw-r--r-- | src/daemons/notes-stats.ts | 4 | ||||
| -rw-r--r-- | src/daemons/server-stats.ts | 4 | ||||
| -rw-r--r-- | src/misc/queue.ts | 33 |
3 files changed, 4 insertions, 37 deletions
diff --git a/src/daemons/notes-stats.ts b/src/daemons/notes-stats.ts index 3bc0269dde..1de7a98523 100644 --- a/src/daemons/notes-stats.ts +++ b/src/daemons/notes-stats.ts @@ -1,11 +1,11 @@ import * as childProcess from 'child_process'; +import * as Deque from 'double-ended-queue'; import Xev from 'xev'; -import Queue from '../misc/queue'; const ev = new Xev(); export default function() { - const log = new Queue<any>(); + const log = new Deque<any>(); const p = childProcess.fork(__dirname + '/notes-stats-child.js'); diff --git a/src/daemons/server-stats.ts b/src/daemons/server-stats.ts index b435c12e55..31560935b2 100644 --- a/src/daemons/server-stats.ts +++ b/src/daemons/server-stats.ts @@ -1,8 +1,8 @@ import * as os from 'os'; import * as sysUtils from 'systeminformation'; import * as diskusage from 'diskusage'; +import * as Deque from 'double-ended-queue'; import Xev from 'xev'; -import Queue from '../misc/queue'; const osUtils = require('os-utils'); const ev = new Xev(); @@ -13,7 +13,7 @@ const interval = 1000; * Report server stats regularly */ export default function() { - const log = new Queue<any>(); + const log = new Deque<any>(); ev.on('requestServerStatsLog', id => { ev.emit('serverStatsLog:' + id, log.toArray()); diff --git a/src/misc/queue.ts b/src/misc/queue.ts deleted file mode 100644 index 410878ba8b..0000000000 --- a/src/misc/queue.ts +++ /dev/null @@ -1,33 +0,0 @@ -type Node<T> = { value: T, next: Node<T> }; - -export default class Queue<T> { - private top: Node<T> = null; - private rear: Node<T> = null; - public length: number = 0; - - public push(value: T): void { - const node: Node<T> = { value, next: null }; - if (this.top === null) { - this.top = node; - this.rear = node; - } else { - this.rear.next = node; - this.rear = node; - } - this.length++; - } - - public pop(): void { - this.top = this.top.next; - if (this.top == null) this.rear = null; - this.length--; - } - - public toArray(): T[] { - const arr: T[] = Array<T>(this.length); - for (let node = this.top, i = 0; node !== null; node = node.next, i++) { - arr[i] = node.value; - } - return arr; - } -} |