Why is String.fromCodePoint() in diff-match-patch (js version) limited to 65535 characters?

Viewed 60

'm trying to use diff-match-patch (Word Mode) when working with large files to get around the limitation associated with String.fromCharCode and the 65535 characters limit, I used String.fromCodePoint as suggested here. But the problem still remained when 65535 characters were exceeded. Example:

diff_match_patch.prototype.diff_linesToChars_ = function(text1, text2) {
  var lineArray = [];
  var lineHash = {};
  lineArray[0] = '';
  function diff_linesToCharsMunge_(text) {
    var chars = '';
    var lineStart = 0;
    var lineEnd = -1;
    var lineArrayLength = lineArray.length;
    while (lineEnd < text.length - 1) {
      lineEnd = text.indexOf(' ', lineStart);
      if (lineEnd == -1) {
        lineEnd = text.length - 1;
      }
      var line = text.substring(lineStart, lineEnd + 1);
      if (lineHash.hasOwnProperty ? lineHash.hasOwnProperty(line) :
          (lineHash[line] !== undefined)) {
        //chars += String.fromCharCode(lineHash[line]);
        chars += String.fromCodePoint(lineHash[line]);
      } else {
        if (lineArrayLength == maxLines) {
          line = text.substring(lineStart);
          lineEnd = text.length;
        }
        //chars += String.fromCharCode(lineArrayLength);
        chars += String.fromCodePoint(lineArrayLength);
        lineHash[line] = lineArrayLength;
        lineArray[lineArrayLength++] = line;
      }
      lineStart = lineEnd + 1;
    }
    return chars;
  }
  var maxLines = 743000;
  var chars1 = diff_linesToCharsMunge_(text1);
  maxLines = 1114111;
  var chars2 = diff_linesToCharsMunge_(text2);
  return {chars1: chars1, chars2: chars2, lineArray: lineArray};
};

diff_match_patch.prototype.diff_charsToLines_ = function(diffs, lineArray) {
  for (var i = 0; i < diffs.length; i++) {
    var chars = diffs[i][1];
    var text = [];
    for (var j = 0; j < chars.length; j++) {
      //text[j] = lineArray[chars.charCodeAt(j)];
      text[j] = lineArray[chars.codePointAt(j)];
    }
    diffs[i][1] = text.join('');
  }
};
0 Answers
Related