Skip to content

Commit

Permalink
Optimized cloneFragment for size and speed
Browse files Browse the repository at this point in the history
  • Loading branch information
Havunen committed Jun 8, 2020
1 parent 1af165f commit 85eba12
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 22 deletions.
4 changes: 2 additions & 2 deletions fixtures/browser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
"author": "",
"license": "MIT",
"devDependencies": {
"@babel/core": "7.10.1",
"@babel/core": "7.10.2",
"@babel/helper-replace-supers": "7.10.1",
"@babel/plugin-proposal-class-properties": "7.10.1",
"@babel/plugin-proposal-decorators": "7.10.1",
"@babel/plugin-proposal-object-rest-spread": "7.10.1",
"@babel/preset-env": "7.10.1",
"@babel/preset-env": "7.10.2",
"babel-loader": "^8.1.0",
"jasmine-core": "^3.5.0",
"karma": "^5.0.9",
Expand Down
16 changes: 8 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,14 +79,14 @@
"test:package": "node fixtures/packaging/build-all.js"
},
"devDependencies": {
"@babel/core": "^7.10.1",
"@babel/core": "^7.10.2",
"@babel/plugin-proposal-class-properties": "7.10.1",
"@babel/preset-env": "7.10.1",
"@babel/preset-env": "7.10.2",
"@babel/preset-typescript": "^7.10.1",
"@rollup/plugin-alias": "^3.1.0",
"@rollup/plugin-alias": "^3.1.1",
"@types/history": "^4.7.6",
"@types/jest": "^25.2.3",
"@types/node": "^14.0.5",
"@types/node": "^14.0.12",
"babel-core": "^7.0.0-bridge.0",
"babel-jest": "^26.0.1",
"babel-plugin-inferno": "6.1.1",
Expand All @@ -103,8 +103,8 @@
"jest-silent-reporter": "^0.2.1",
"jsdom": "^16.2.2",
"lerna": "3.22.0",
"lint-staged": "^10.2.7",
"madge": "^3.9.0",
"lint-staged": "^10.2.9",
"madge": "^3.9.1",
"merge-dirs": "^0.2.1",
"minimist": "^1.2.5",
"mobx": "4.8.0",
Expand All @@ -113,7 +113,7 @@
"pre-commit": "^1.2.2",
"prettier": "^2.0.5",
"rimraf": "^3.0.2",
"rollup": "2.11.2",
"rollup": "2.15.0",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-buble": "^0.19.8",
"rollup-plugin-commonjs": "^10.1.0",
Expand All @@ -124,6 +124,6 @@
"sinon": "^9.0.2",
"tslint": "^6.1.2",
"tslint-config-prettier": "^1.18.0",
"typescript": "3.9.3"
"typescript": "3.9.5"
}
}
17 changes: 5 additions & 12 deletions packages/inferno/src/core/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,21 +207,14 @@ export function normalizeProps(vNode) {
* But not normalize, because otherwise those possibly get KEY and re-mount
*/
function cloneFragment(vNodeToClone) {
let clonedChildren;
const oldChildren = vNodeToClone.children;
const childFlags = vNodeToClone.childFlags;

if (childFlags === ChildFlags.HasVNodeChildren) {
clonedChildren = directClone(oldChildren as VNode);
} else if (childFlags & ChildFlags.MultipleChildren) {
clonedChildren = [];

for (let i = 0, len = oldChildren.length; i < len; ++i) {
clonedChildren.push(directClone(oldChildren[i]));
}
}

return createFragment(clonedChildren, childFlags, vNodeToClone.key);
return createFragment(
childFlags === ChildFlags.HasVNodeChildren ? directClone(oldChildren as VNode) : oldChildren.map(directClone),
childFlags,
vNodeToClone.key
);
}

export function directClone(vNodeToClone: VNode): VNode {
Expand Down

0 comments on commit 85eba12

Please sign in to comment.