From 60f8b080374a41ad172a789f18c2c8f01dc4a05c Mon Sep 17 00:00:00 2001 From: Andrey Sidorov Date: Wed, 18 May 2016 20:22:24 +1000 Subject: [PATCH] add unused IDs buffer --- lib/xcore.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/xcore.js b/lib/xcore.js index cf073e4..17eb9ed 100644 --- a/lib/xcore.js +++ b/lib/xcore.js @@ -119,6 +119,7 @@ XClient.prototype.init = function(stream) this.startHandshake(); this._closing = false; + this._unusedIds = []; } // TODO: close() = set 'closing' flag, watch it in replies and writeQueue, terminate if empty @@ -247,12 +248,17 @@ XClient.prototype.importRequestsFromTemplates = function(target, reqs) XClient.prototype.AllocID = function() { - // TODO: handle overflow (XCMiscGetXIDRange from XC_MISC ext) - // TODO: unused id buffer - this.display.rsrc_id++; - return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base; -} + if (this._unusedIds.length > 0) { + return this._unusedIds.pop(); + } + // TODO: handle overflow (XCMiscGetXIDRange from XC_MISC ext) + this.display.rsrc_id++; + return (this.display.rsrc_id << this.display.rsrc_shift) + this.display.resource_base; +}; +XClient.prototype.ReleaseID = function(id) { + this._unusedIds.push(id); +}; // TODO: move core events unpackers to corereqs.js XClient.prototype.unpackEvent = function(type, seq, extra, code, raw, headerBuf)