浏览代码

Performance optimization. Cache all the things.

Piotrek Koszuliński 5 年之前
父节点
当前提交
adb237b10e
共有 1 个文件被更改,包括 6 次插入3 次删除
  1. 6 3
      packages/ckeditor5-engine/src/model/treewalker.js

+ 6 - 3
packages/ckeditor5-engine/src/model/treewalker.js

@@ -225,7 +225,9 @@ export default class TreeWalker {
 			return { done: true };
 		}
 
-		const node = position.textNode ? position.textNode : position.nodeAfter;
+		// Get node just after the current position.
+		const textNodeAtPosition = position.textNode;
+		const node = textNodeAtPosition ? textNodeAtPosition : position.nodeAfter;
 
 		if ( node instanceof Element ) {
 			if ( !this.shallow ) {
@@ -299,8 +301,9 @@ export default class TreeWalker {
 			return { done: true };
 		}
 
-		// Get node just before current position
-		const node = position.textNode ? position.textNode : position.nodeBefore;
+		// Get node just before the current position.
+		const textNodeAtPosition = position.textNode;
+		const node = textNodeAtPosition ? textNodeAtPosition : position.nodeBefore;
 
 		if ( node instanceof Element ) {
 			position.offset--;