mirror of
https://github.com/ianstormtaylor/slate.git
synced 2025-08-20 06:01:24 +02:00
Remove redundant memoization (#1630)
* Remove memoization from node.getKeys * Remove memoization from methods that are directly backed by AsArray variants * Remove memoization from hasChild/Descendant/Node These are thin wrappers on top of functions that are themselves memoized.
This commit is contained in:
committed by
Ian Storm Taylor
parent
e3abba0a29
commit
324a025ee9
@@ -1693,15 +1693,15 @@ class Node {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
insertNode(index, node) {
|
insertNode(index, node) {
|
||||||
const keys = this.getKeys()
|
const keys = this.getKeysAsArray()
|
||||||
|
|
||||||
if (keys.contains(node.key)) {
|
if (keys.includes(node.key)) {
|
||||||
node = node.regenerateKey()
|
node = node.regenerateKey()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.object != 'text') {
|
if (node.object != 'text') {
|
||||||
node = node.mapDescendants(desc => {
|
node = node.mapDescendants(desc => {
|
||||||
return keys.contains(desc.key) ? desc.regenerateKey() : desc
|
return keys.includes(desc.key) ? desc.regenerateKey() : desc
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1999,22 +1999,15 @@ function assertKey(arg) {
|
|||||||
memoize(
|
memoize(
|
||||||
Node.prototype,
|
Node.prototype,
|
||||||
[
|
[
|
||||||
'getBlocks',
|
|
||||||
'getBlocksAsArray',
|
'getBlocksAsArray',
|
||||||
'getCharacters',
|
|
||||||
'getCharactersAsArray',
|
'getCharactersAsArray',
|
||||||
'getFirstText',
|
'getFirstText',
|
||||||
'getInlines',
|
|
||||||
'getInlinesAsArray',
|
'getInlinesAsArray',
|
||||||
'getKeys',
|
|
||||||
'getKeysAsArray',
|
'getKeysAsArray',
|
||||||
'getLastText',
|
'getLastText',
|
||||||
'getMarks',
|
|
||||||
'getOrderedMarks',
|
|
||||||
'getMarksAsArray',
|
'getMarksAsArray',
|
||||||
'getText',
|
'getText',
|
||||||
'getTextDirection',
|
'getTextDirection',
|
||||||
'getTexts',
|
|
||||||
'getTextsAsArray',
|
'getTextsAsArray',
|
||||||
'isLeafBlock',
|
'isLeafBlock',
|
||||||
'isLeafInline',
|
'isLeafInline',
|
||||||
@@ -2028,14 +2021,10 @@ memoize(
|
|||||||
Node.prototype,
|
Node.prototype,
|
||||||
[
|
[
|
||||||
'areDescendantsSorted',
|
'areDescendantsSorted',
|
||||||
'getActiveMarksAtRange',
|
|
||||||
'getActiveMarksAtRangeAsArray',
|
'getActiveMarksAtRangeAsArray',
|
||||||
'getAncestors',
|
'getAncestors',
|
||||||
'getBlocksAtRange',
|
|
||||||
'getBlocksAtRangeAsArray',
|
'getBlocksAtRangeAsArray',
|
||||||
'getBlocksByType',
|
|
||||||
'getBlocksByTypeAsArray',
|
'getBlocksByTypeAsArray',
|
||||||
'getCharactersAtRange',
|
|
||||||
'getCharactersAtRangeAsArray',
|
'getCharactersAtRangeAsArray',
|
||||||
'getChild',
|
'getChild',
|
||||||
'getClosestBlock',
|
'getClosestBlock',
|
||||||
@@ -2051,17 +2040,10 @@ memoize(
|
|||||||
'getFurthestInline',
|
'getFurthestInline',
|
||||||
'getFurthestAncestor',
|
'getFurthestAncestor',
|
||||||
'getFurthestOnlyChildAncestor',
|
'getFurthestOnlyChildAncestor',
|
||||||
'getInlinesAtRange',
|
|
||||||
'getInlinesAtRangeAsArray',
|
'getInlinesAtRangeAsArray',
|
||||||
'getInlinesByType',
|
|
||||||
'getInlinesByTypeAsArray',
|
'getInlinesByTypeAsArray',
|
||||||
'getMarksAtRange',
|
|
||||||
'getInsertMarksAtRange',
|
|
||||||
'getOrderedMarksAtRange',
|
|
||||||
'getMarksAtRangeAsArray',
|
'getMarksAtRangeAsArray',
|
||||||
'getInsertMarksAtRangeAsArray',
|
'getInsertMarksAtRangeAsArray',
|
||||||
'getMarksByType',
|
|
||||||
'getOrderedMarksByType',
|
|
||||||
'getMarksByTypeAsArray',
|
'getMarksByTypeAsArray',
|
||||||
'getNextBlock',
|
'getNextBlock',
|
||||||
'getNextSibling',
|
'getNextSibling',
|
||||||
@@ -2077,11 +2059,7 @@ memoize(
|
|||||||
'getPreviousSibling',
|
'getPreviousSibling',
|
||||||
'getPreviousText',
|
'getPreviousText',
|
||||||
'getTextAtOffset',
|
'getTextAtOffset',
|
||||||
'getTextsAtRange',
|
|
||||||
'getTextsAtRangeAsArray',
|
'getTextsAtRangeAsArray',
|
||||||
'hasChild',
|
|
||||||
'hasDescendant',
|
|
||||||
'hasNode',
|
|
||||||
'hasVoidParent',
|
'hasVoidParent',
|
||||||
'validate',
|
'validate',
|
||||||
],
|
],
|
||||||
|
Reference in New Issue
Block a user