Skip to content
This repository has been archived by the owner on Nov 8, 2024. It is now read-only.

Commit

Permalink
perf(core): use find over filter()[0]
Browse files Browse the repository at this point in the history
This change brings a decent performance improvement when you are using
`valueOf` with a lot of provided reusable elements
  • Loading branch information
kylef committed Jun 20, 2019
1 parent 698524e commit 40de393
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 6 additions & 0 deletions packages/api-elements/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# API Elements (JavaScript) CHANGELOG

## Master

### Enhancements

- Performance of the `valueOf` has been improved under certain cases.

## 0.2.0 (2019-06-11)

### Breaking
Expand Down
4 changes: 2 additions & 2 deletions packages/api-elements/lib/define-value-of.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = (namespace) => {

if (elements) {
if (e.element === 'ref') {
const result = elements.filter(el => el.id.equals(e.content))[0];
const result = elements.find(el => el.id.equals(e.content));
const inheritedElements = elements.filter(el => !el.id.equals(e.content));

if (e.path && e.path.toValue() === 'content') {
Expand All @@ -139,7 +139,7 @@ module.exports = (namespace) => {
return mapValue(result, opts, f, inheritedElements);
}

const result = elements.filter(el => el.id.equals(e.element))[0];
const result = elements.find(el => el.id.equals(e.element));
if (result) {
const inheritedElements = elements.filter(el => !el.id.equals(e.element));
return mapValue(result, opts, f, inheritedElements);
Expand Down

0 comments on commit 40de393

Please sign in to comment.