Skip to content

Commit

Permalink
refactor(classes): use cached length for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
nartc committed Jul 8, 2021
1 parent 697ee81 commit 21435b7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 5 additions & 1 deletion packages/classes/src/lib/storages/class-metadata.storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,11 @@ export class ClassMetadataStorage implements MetadataStorage<Constructible> {
}

const resultMetadataList: Array<Metadata<Constructible>> = [];
for (let i = 0; i < metadataList.length; i++) {
for (
let i = 0, metadataListLen = metadataList.length;
i < metadataListLen;
i++
) {
const metadata = metadataList[i];
// skip existing
if (
Expand Down
3 changes: 1 addition & 2 deletions packages/classes/src/lib/utils/instantiate.util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,7 @@ export function instantiate<TModel extends Dictionary<TModel>>(
// initialize a nestedConstructible with empty []
const nestedConstructible: unknown[] = [];

// reversed loop
for (let i = 0; i < metadata.length; i++) {
for (let i = 0, metadataLen = metadata.length; i < metadataLen; i++) {
// destructure
const [key, meta, isGetterOnly] = metadata[i];

Expand Down

0 comments on commit 21435b7

Please sign in to comment.