From 9766dff5d8ad8e157a6a1a170793b048629d286c Mon Sep 17 00:00:00 2001 From: ghosthope Date: Fri, 23 Sep 2016 16:57:40 +0300 Subject: [PATCH 1/4] Javascript performance. Was add new string.hash function - murmurhash3_gc.js (https://github.com/garycourt/murmurhash-js/blob/master/murmurhash3_gc.js). Performance of the function increased in two times --- runtime/JavaScript/src/antlr4/Utils.js | 69 +++++++++++++++++++++----- 1 file changed, 57 insertions(+), 12 deletions(-) diff --git a/runtime/JavaScript/src/antlr4/Utils.js b/runtime/JavaScript/src/antlr4/Utils.js index b47e75872..6b54da305 100644 --- a/runtime/JavaScript/src/antlr4/Utils.js +++ b/runtime/JavaScript/src/antlr4/Utils.js @@ -2,18 +2,63 @@ function arrayToString(a) { return "[" + a.join(", ") + "]"; } -String.prototype.hashCode = function(s) { - var hash = 0; - if (this.length === 0) { - return hash; - } - for (var i = 0; i < this.length; i++) { - var character = this.charCodeAt(i); - hash = ((hash << 5) - hash) + character; - hash = hash & hash; // Convert to 32bit integer - } - return hash; -}; + String.prototype.seed = String.prototype.seed || Math.round(Math.random() * Math.pow(2, 32));; + + String.prototype.hashCode = function () { + var remainder, bytes, h1, h1b, c1, c1b, c2, c2b, k1, i, + key = this.toString(); + + remainder = key.length & 3; // key.length % 4 + bytes = key.length - remainder; + h1 = String.prototype.seed; + c1 = 0xcc9e2d51; + c2 = 0x1b873593; + i = 0; + + while (i < bytes) { + k1 = + ((key.charCodeAt(i) & 0xff)) | + ((key.charCodeAt(++i) & 0xff) << 8) | + ((key.charCodeAt(++i) & 0xff) << 16) | + ((key.charCodeAt(++i) & 0xff) << 24); + ++i; + + k1 = ((((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16))) & 0xffffffff; + k1 = (k1 << 15) | (k1 >>> 17); + k1 = ((((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16))) & 0xffffffff; + + h1 ^= k1; + h1 = (h1 << 13) | (h1 >>> 19); + h1b = ((((h1 & 0xffff) * 5) + ((((h1 >>> 16) * 5) & 0xffff) << 16))) & 0xffffffff; + h1 = (((h1b & 0xffff) + 0x6b64) + ((((h1b >>> 16) + 0xe654) & 0xffff) << 16)); + } + + k1 = 0; + + switch (remainder) { + case 3: + k1 ^= (key.charCodeAt(i + 2) & 0xff) << 16; + case 2: + k1 ^= (key.charCodeAt(i + 1) & 0xff) << 8; + case 1: + k1 ^= (key.charCodeAt(i) & 0xff); + + k1 = (((k1 & 0xffff) * c1) + ((((k1 >>> 16) * c1) & 0xffff) << 16)) & 0xffffffff; + k1 = (k1 << 15) | (k1 >>> 17); + k1 = (((k1 & 0xffff) * c2) + ((((k1 >>> 16) * c2) & 0xffff) << 16)) & 0xffffffff; + h1 ^= k1; + } + + h1 ^= key.length; + + h1 ^= h1 >>> 16; + h1 = (((h1 & 0xffff) * 0x85ebca6b) + ((((h1 >>> 16) * 0x85ebca6b) & 0xffff) << 16)) & 0xffffffff; + h1 ^= h1 >>> 13; + h1 = ((((h1 & 0xffff) * 0xc2b2ae35) + ((((h1 >>> 16) * 0xc2b2ae35) & 0xffff) << 16))) & 0xffffffff; + h1 ^= h1 >>> 16; + + return h1 >>> 0; + }; function standardEqualsFunction(a,b) { return a.equals(b); From 04e9078dd98a90e3d6b93d22936dd4c1ef46c0fd Mon Sep 17 00:00:00 2001 From: ghosthope Date: Wed, 23 Nov 2016 13:58:43 +0300 Subject: [PATCH 2/4] from master --- .../test/runtime/javascript/chrome/chromedriver.bin | Bin .../src/org/antlr/v4/runtime/atn/ATNConfigSet.java | 0 .../antlr/v4/runtime/atn/ParserATNSimulator.java | 0 runtime/Python2/src/antlr4/atn/ATNConfigSet.py | 0 .../Python2/src/antlr4/atn/ParserATNSimulator.py | 0 runtime/Python3/bin/pygrun | 0 runtime/Python3/bin/pygrun.bat | 0 runtime/Python3/src/antlr4/atn/ATNConfigSet.py | 0 .../Python3/src/antlr4/atn/ParserATNSimulator.py | 0 9 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/chrome/chromedriver.bin mode change 100755 => 100644 runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java mode change 100755 => 100644 runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java mode change 100755 => 100644 runtime/Python2/src/antlr4/atn/ATNConfigSet.py mode change 100755 => 100644 runtime/Python2/src/antlr4/atn/ParserATNSimulator.py mode change 100755 => 100644 runtime/Python3/bin/pygrun mode change 100755 => 100644 runtime/Python3/bin/pygrun.bat mode change 100755 => 100644 runtime/Python3/src/antlr4/atn/ATNConfigSet.py mode change 100755 => 100644 runtime/Python3/src/antlr4/atn/ParserATNSimulator.py diff --git a/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/chrome/chromedriver.bin b/runtime-testsuite/test/org/antlr/v4/test/runtime/javascript/chrome/chromedriver.bin old mode 100755 new mode 100644 diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ATNConfigSet.java old mode 100755 new mode 100644 diff --git a/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java b/runtime/Java/src/org/antlr/v4/runtime/atn/ParserATNSimulator.java old mode 100755 new mode 100644 diff --git a/runtime/Python2/src/antlr4/atn/ATNConfigSet.py b/runtime/Python2/src/antlr4/atn/ATNConfigSet.py old mode 100755 new mode 100644 diff --git a/runtime/Python2/src/antlr4/atn/ParserATNSimulator.py b/runtime/Python2/src/antlr4/atn/ParserATNSimulator.py old mode 100755 new mode 100644 diff --git a/runtime/Python3/bin/pygrun b/runtime/Python3/bin/pygrun old mode 100755 new mode 100644 diff --git a/runtime/Python3/bin/pygrun.bat b/runtime/Python3/bin/pygrun.bat old mode 100755 new mode 100644 diff --git a/runtime/Python3/src/antlr4/atn/ATNConfigSet.py b/runtime/Python3/src/antlr4/atn/ATNConfigSet.py old mode 100755 new mode 100644 diff --git a/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py b/runtime/Python3/src/antlr4/atn/ParserATNSimulator.py old mode 100755 new mode 100644 From cc59a359aedb3c99207b07346df85bda96b46244 Mon Sep 17 00:00:00 2001 From: ghosthope Date: Fri, 25 Nov 2016 15:36:24 +0300 Subject: [PATCH 3/4] contributor name was added --- contributors.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/contributors.txt b/contributors.txt index 687eeaf20..c2e9693df 100644 --- a/contributors.txt +++ b/contributors.txt @@ -92,3 +92,4 @@ YYYY/MM/DD, github id, Full name, email 2016/03/27, beardlybread, Bradley Steinbacher, bradley.j.steinbacher@gmail.com 2016/03/29, msteiger, Martin Steiger, antlr@martin-steiger.de 2016/03/28, gagern, Martin von Gagern, gagern@ma.tum.de +2016/09/23, ghosthop, Dmitry Shakhtanov, sudstrike@gmail.com From a20a87fad6e570cb5e6993d12a48789f8ae5ce5c Mon Sep 17 00:00:00 2001 From: ghosthope Date: Fri, 25 Nov 2016 17:56:04 +0300 Subject: [PATCH 4/4] typo --- contributors.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contributors.txt b/contributors.txt index c2e9693df..032495efa 100644 --- a/contributors.txt +++ b/contributors.txt @@ -92,4 +92,4 @@ YYYY/MM/DD, github id, Full name, email 2016/03/27, beardlybread, Bradley Steinbacher, bradley.j.steinbacher@gmail.com 2016/03/29, msteiger, Martin Steiger, antlr@martin-steiger.de 2016/03/28, gagern, Martin von Gagern, gagern@ma.tum.de -2016/09/23, ghosthop, Dmitry Shakhtanov, sudstrike@gmail.com +2016/09/23, ghosthope, Dmitry Shakhtanov, sudstrike@gmail.com