Created
August 7, 2018 23:06
-
-
Save jridgewell/835b61b0a008a197315377e209005d20 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/src/node_data.ts b/src/node_data.ts | |
index 860c51e..0d712c0 100644 | |
--- a/src/node_data.ts | |
+++ b/src/node_data.ts | |
@@ -61,8 +61,17 @@ export class NodeData { | |
return !!this._attrsArr; | |
} | |
- getAttrsArr(): any[] { | |
- return this._attrsArr || (this._attrsArr = []); | |
+ getAttrsArr(length?: number): any[] { | |
+ let attrs = this._attrsArr; | |
+ if (attrs) { | |
+ return attrs; | |
+ } | |
+ if (length && length > 0) { | |
+ attrs = new Array(length); | |
+ } else { | |
+ attrs = []; | |
+ } | |
+ return (this._attrsArr = attrs); | |
} | |
} | |
@@ -145,18 +154,18 @@ function recordAttributes(node: Element, data: NodeData) { | |
return; | |
} | |
- const attrsArr = data.getAttrsArr(); | |
+ const attrsArr = data.getAttrsArr(length); | |
// Use a cached length. The attributes array is really a live NamedNodeMap, | |
// which exists as a DOM "Host Object" (probably as C++ code). This makes the | |
// usual constant length iteration very difficult to optimize in JITs. | |
- for (let i = 0; i < length; i += 1) { | |
+ for (let i = 0, j = 0; i < length; i += 1, j += 2) { | |
const attr = attributes[i]; | |
const name = attr.name; | |
const value = attr.value; | |
- attrsArr.push(name); | |
- attrsArr.push(value); | |
+ attrsArr[j] = name; | |
+ attrsArr[j + 1] = value; | |
} | |
} | |
diff --git a/src/virtual_elements.ts b/src/virtual_elements.ts | |
index 221f3e4..2013dcb 100644 | |
--- a/src/virtual_elements.ts | |
+++ b/src/virtual_elements.ts | |
@@ -133,8 +133,11 @@ function elementOpen( | |
return node; | |
} | |
- const attrsArr = data.getAttrsArr(); | |
- const isNew = !attrsArr.length; | |
+ let isNew = !data.hasAttrsArr(); | |
+ const attrsArr = data.getAttrsArr(arguments.length - ATTRIBUTES_OFFSET); | |
+ if (!isNew) { | |
+ isNew = !attrsArr.length; | |
+ } | |
/* | |
* Checks to see if one or more attributes have changed for a given Element. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment