Skip to content

perf: use native Array methods instead of for loop #3519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions packages/compiler-core/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,16 +137,13 @@ export function findDir(
name: string | RegExp,
allowEmpty: boolean = false
): DirectiveNode | undefined {
for (let i = 0; i < node.props.length; i++) {
const p = node.props[i]
if (
const prop = node.props.find(
p =>
p.type === NodeTypes.DIRECTIVE &&
(allowEmpty || p.exp) &&
(isString(name) ? p.name === name : name.test(p.name))
) {
return p
}
}
)
return prop as DirectiveNode
}

export function findProp(
Expand Down
27 changes: 8 additions & 19 deletions packages/runtime-core/src/componentRenderUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,15 +327,10 @@ export function shouldUpdateComponent(
return hasPropsChanged(prevProps, nextProps!, emits)
} else if (patchFlag & PatchFlags.PROPS) {
const dynamicProps = nextVNode.dynamicProps!
for (let i = 0; i < dynamicProps.length; i++) {
const key = dynamicProps[i]
if (
nextProps![key] !== prevProps![key] &&
!isEmitListener(emits, key)
) {
return true
}
}
return dynamicProps.some(
key =>
nextProps![key] !== prevProps![key] && !isEmitListener(emits, key)
)
}
} else {
// this path is only taken by manually written render functions
Expand Down Expand Up @@ -369,16 +364,10 @@ function hasPropsChanged(
if (nextKeys.length !== Object.keys(prevProps).length) {
return true
}
for (let i = 0; i < nextKeys.length; i++) {
const key = nextKeys[i]
if (
nextProps[key] !== prevProps[key] &&
!isEmitListener(emitsOptions, key)
) {
return true
}
}
return false
return nextKeys.some(
key =>
nextProps[key] !== prevProps[key] && !isEmitListener(emitsOptions, key)
)
}

export function updateHOCHostEl(
Expand Down
8 changes: 1 addition & 7 deletions packages/server-renderer/src/helpers/ssrRenderSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,7 @@ export function ssrRenderSlot(
} else {
// ssr slot.
// check if the slot renders all comments, in which case use the fallback
let isEmptySlot = true
for (let i = 0; i < slotBuffer.length; i++) {
if (!isComment(slotBuffer[i])) {
isEmptySlot = false
break
}
}
let isEmptySlot = slotBuffer.every(s => isComment(s))
if (isEmptySlot) {
if (fallbackRenderFn) {
fallbackRenderFn()
Expand Down