Skip to content
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

Avoid extra meta lookups in Ember.set. #17058

Merged
merged 1 commit into from
Dec 8, 2018
Merged
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
3 changes: 1 addition & 2 deletions packages/@ember/-internals/metal/lib/property_get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ export function get(obj: object, keyName: string): any {
let isFunction = type === 'function';
let isObjectLike = isObject || isFunction;

let descriptor;
let value: any;

if (isObjectLike) {
Expand All @@ -105,7 +104,7 @@ export function get(obj: object, keyName: string): any {
if (tracker) tracker.add(tagForProperty(obj, keyName));
}

descriptor = descriptorFor(obj, keyName);
let descriptor = descriptorFor(obj, keyName);
if (descriptor !== undefined) {
return descriptor.get(obj, keyName);
}
Expand Down
10 changes: 4 additions & 6 deletions packages/@ember/-internals/metal/lib/property_set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ export function set(obj: object, keyName: string, value: any, tolerant?: boolean
return setPath(obj, keyName, value, tolerant);
}

let possibleDesc = descriptorFor(obj, keyName);
let meta = peekMeta(obj);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if we call peekMeta(obj) early it can be reused both in descriptorFor and notifyPropertyChange

let descriptor = descriptorFor(obj, keyName, meta);

if (possibleDesc !== undefined) {
/* computed property */
possibleDesc.set(obj, keyName, value);
if (descriptor !== undefined) {
descriptor.set(obj, keyName, value);
return value;
}

Expand All @@ -100,8 +100,6 @@ export function set(obj: object, keyName: string, value: any, tolerant?: boolean
/* unknown property */
(obj as ExtendedObject).setUnknownProperty!(keyName, value);
} else {
let meta = peekMeta(obj);

if (DEBUG) {
setWithMandatorySetter<any, any>(meta, obj, keyName, value);
} else {
Expand Down