+
+ // Avoid comparing long text character by character.
+ let step = 1;
+ while (true) {
+ step = Math.min(step * 2, N - x, M - y);
+ if (!step) break;
+ if (a.substr(x, step) == b.substr(y, step)) {
+ x += step;
+ y += step;
+ } else {
+ break;
+ }
+ }