Skip to content

Commit

Permalink
Change array filter with better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrii Kirmas committed Feb 27, 2021
1 parent 8cdcf27 commit 4ac536f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ function resolver(
keys[i] = act
}

//TODO Compare `.flat()`, `.filter(Boolean)` or `.filter(idfn)`
const filtered = keys.filter(Boolean)
//TODO https://measurethat.net/Benchmarks/Show/11866/1/arrayfilter
const filtered = keys.filter(x => x)

return filtered.length === 0 ? EMPTY_ARRAY : filtered
}
Expand All @@ -65,4 +65,4 @@ function joinWithLead(value: Falsy|ClassHash, arr: undefined | string | readonly
return str2

return `${str1} ${str2}`
}
}
4 changes: 2 additions & 2 deletions src/sandbox/double-shape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function _doubleShape<
) {
const {applied, classnames, className} = ctx
//@ts-expect-error
, nextApplied = !applied ? [] : applied.push(...args.filter(Boolean)) as Record<U | keyof A, ClassHash|boolean>[]
, nextApplied = !applied ? [] : applied.push(...args.filter(x => x)) as Record<U | keyof A, ClassHash|boolean>[]

, host = <
// T extends {[K in Exclude<S, U | keyof A>]?: boolean} | {[K in Exclude<S, U | keyof A>]?: ClassHash}
Expand Down Expand Up @@ -83,7 +83,7 @@ function _doubleShape<
withClassName && className,
injection,
args.flat().join(" ")
].filter(Boolean)
].filter(x => x)
.join(" ")

host["className"] = calced
Expand Down

0 comments on commit 4ac536f

Please sign in to comment.