From df7d21f63f21d821757676f0bc7dae84b52e9eac Mon Sep 17 00:00:00 2001 From: Philippe Proulx Date: Sat, 5 Oct 2013 15:20:42 -0400 Subject: [PATCH] weechat-protocol.js: use pointer instead of slicing I don't know if this changes anything to performance, but my instinct tells me that it's better to update a pointer within a big array to get slices than creating a new slice each time. Perhaps the JS engine is clever enough to not create a copy each time and only update its internal references of the array bounds, but just in case... --- js/weechat-protocol.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/js/weechat-protocol.js b/js/weechat-protocol.js index 4cb3d3c..672bec7 100644 --- a/js/weechat-protocol.js +++ b/js/weechat-protocol.js @@ -102,9 +102,9 @@ WeeChatProtocol.prototype = { return ""; }, _getSlice: function(length) { - var slice = this.data.slice(0, length); + var slice = this._data.slice(this._dataAt, this._dataAt + length); - this.data = this.data.slice(length); + this._dataAt += length; return slice; }, @@ -148,11 +148,13 @@ WeeChatProtocol.prototype = { return values; }, _setData: function (data) { - this.data = data; + this._data = data; }, parse: function(data) { var self = this; + this._setData(data); + this._dataAt = 0; var header = this._getHeader(); var id = this._getId();