From ff831eba7d85d882af12c4fa6e05cd5ea576f6c9 Mon Sep 17 00:00:00 2001 From: themithy <11431578+themithy@users.noreply.github.com> Date: Mon, 19 Aug 2019 18:37:38 +0200 Subject: [PATCH] Deduplicate dirty paths for normalization. (#2916) * Deduplicate dirty paths for normalization. * Update editor.js --- packages/slate/src/controllers/editor.js | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/slate/src/controllers/editor.js b/packages/slate/src/controllers/editor.js index 5ef061a564..10bd3efcd0 100644 --- a/packages/slate/src/controllers/editor.js +++ b/packages/slate/src/controllers/editor.js @@ -107,7 +107,20 @@ class Editor { return transformed.toArray() }) - this.tmp.dirty = Array.prototype.concat.apply(newDirtyPaths, dirty) + const pathIndex = {} + const dirtyPaths = Array.prototype.concat.apply(newDirtyPaths, dirty) + this.tmp.dirty = [] + + // PERF: De-dupe the paths so we don't do extra normalization. + dirtyPaths.forEach(dirtyPath => { + const key = dirtyPath.join(',') + + if (!pathIndex[key]) { + this.tmp.dirty.push(dirtyPath) + } + + pathIndex[key] = true + }) // If we're not already, queue the flushing process on the next tick. if (!this.tmp.flushing) {