forked from jasder/antlr
Merge pull request #2905 from antlr/fix-javascript-perf-issue
Fix #2902
This commit is contained in:
commit
2e4bf8196a
|
@ -4,7 +4,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
const RuleContext = require('./RuleContext');
|
const RuleContext = require('./RuleContext');
|
||||||
const {Hash, Map} = require('./Utils');
|
const {Hash, Map, equalArrays} = require('./Utils');
|
||||||
|
|
||||||
class PredictionContext {
|
class PredictionContext {
|
||||||
constructor(cachedHashCode) {
|
constructor(cachedHashCode) {
|
||||||
|
@ -249,8 +249,8 @@ class ArrayPredictionContext extends PredictionContext {
|
||||||
} else if (this.hashCode() !== other.hashCode()) {
|
} else if (this.hashCode() !== other.hashCode()) {
|
||||||
return false; // can't be same if hash is different
|
return false; // can't be same if hash is different
|
||||||
} else {
|
} else {
|
||||||
return this.returnStates === other.returnStates &&
|
return equalArrays(this.returnStates, other.returnStates) &&
|
||||||
this.parents === other.parents;
|
equalArrays(this.parents, other.parents);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -557,7 +557,7 @@ function mergeArrays(a, b, rootIsWildcard, mergeCache) {
|
||||||
while (i < a.returnStates.length && j < b.returnStates.length) {
|
while (i < a.returnStates.length && j < b.returnStates.length) {
|
||||||
const a_parent = a.parents[i];
|
const a_parent = a.parents[i];
|
||||||
const b_parent = b.parents[j];
|
const b_parent = b.parents[j];
|
||||||
if (a.returnStates[i] === b.returnStates[j]) {
|
if (equalArrays(a.returnStates[i], b.returnStates[j])) {
|
||||||
// same payload (stack tops are equal), must yield merged singleton
|
// same payload (stack tops are equal), must yield merged singleton
|
||||||
const payload = a.returnStates[i];
|
const payload = a.returnStates[i];
|
||||||
// $+$ = $
|
// $+$ = $
|
||||||
|
|
|
@ -430,7 +430,7 @@ function equalArrays(a, b) {
|
||||||
for (let i = 0; i < a.length; i++) {
|
for (let i = 0; i < a.length; i++) {
|
||||||
if (a[i] == b[i])
|
if (a[i] == b[i])
|
||||||
continue;
|
continue;
|
||||||
if (!a[i].equals(b[i]))
|
if (!a[i].equals || !a[i].equals(b[i]))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Reference in New Issue