Skip to content

Commit 0328387

Browse files
committed
Call defineProperties in bulk with list of descriptors for performance
1 parent dc706d2 commit 0328387

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/class-model.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -465,21 +465,21 @@ function initializeVolatiles(result: Record<string, any>, node: Record<string, a
465465
}
466466

467467
function bindToSelf<T extends Record<string, any>>(self: object, inputs: T): T {
468-
const outputs = {} as T;
469468
const descriptors = Object.getOwnPropertyDescriptors(inputs);
470469
for (const key in descriptors) {
471-
const property = descriptors[key];
472-
if (typeof property.value === "function") {
473-
property.value = property.value.bind(self);
470+
const descriptor = descriptors[key];
471+
if (typeof descriptor.value === "function") {
472+
descriptor.value = descriptor.value.bind(self);
474473
}
475-
if (typeof property.get === "function") {
476-
property.get = property.get.bind(self);
474+
if (typeof descriptor.get === "function") {
475+
descriptor.get = descriptor.get.bind(self);
477476
}
478-
if (typeof property.set === "function") {
479-
property.set = property.set.bind(self);
477+
if (typeof descriptor.set === "function") {
478+
descriptor.set = descriptor.set.bind(self);
480479
}
481-
Object.defineProperty(outputs, key, property);
482480
}
481+
const outputs = {} as T;
482+
Object.defineProperties(outputs, descriptors);
483483
return outputs;
484484
}
485485

0 commit comments

Comments
 (0)