max stack size on chrome is smaller now

This commit is contained in:
nightwing 2014-12-21 12:22:17 +04:00
commit 56cb246c78

View file

@ -571,11 +571,12 @@ var Document = function(textOrLines) {
var isInsert = delta.action == "insert";
// An empty range is a NOOP.
if (isInsert ? delta.lines.length <= 1 && !delta.lines[0]
: !Range.comparePoints(delta.start, delta.end))
: !Range.comparePoints(delta.start, delta.end)) {
return;
}
if (isInsert && delta.lines.length > 0xF000)
this.$splitAndapplyLargeDelta(delta, 0xF000);
if (isInsert && delta.lines.length > 20000)
this.$splitAndapplyLargeDelta(delta, 20000);
// Apply.
applyDelta(this.$lines, delta, doNotValidate);
@ -585,8 +586,8 @@ var Document = function(textOrLines) {
this.$splitAndapplyLargeDelta = function(delta, MAX) {
// Split large insert deltas. This is necessary because:
// 1. We need to support splicing delta lines into the document via $lines.splice.apply(...)
// 2. fn.apply() doesn't work for a large number of params. The smallest threshold is on safari 0xFFFF.
// we use 0xF000 to leave some space for actual stack
// 2. fn.apply() doesn't work for a large number of params. The smallest threshold is on chrome 40 ~42000.
// we use 20000 to leave some space for actual stack
//
// To Do: Ideally we'd be consistent and also split 'delete' deltas. We don't do this now, because delete
// delta handling is too slow. If we make delete delta handling faster we can split all large deltas
@ -623,10 +624,9 @@ var Document = function(textOrLines) {
* @param {Object} delta A delta object (can include "insert" and "remove" actions)
**/
this.revertDelta = function(delta) {
var range = Range.fromPoints(delta.start, delta.end);
this.applyDelta({
start: range.start,
end: range.end,
start: this.clonePos(delta.start),
end: this.clonePos(delta.end),
action: (delta.action == "insert" ? "remove" : "insert"),
lines: delta.lines.slice()
});