Skip to content

Commit

Permalink
Do not create unneeded Promise instances
Browse files Browse the repository at this point in the history
  • Loading branch information
jridgewell committed Feb 18, 2016
1 parent e40a569 commit e75c9f2
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion builtins/amp-ad.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ export function installAd(win) {
}
return cidForOrNull(this.getWin()).then(cidService => {
if (!cidService) {
return Promise.resolve();
return;
}
let consent = Promise.resolve();
const consentId = this.element.getAttribute(
Expand Down
2 changes: 1 addition & 1 deletion src/custom-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ export function createAmpElementProto(win, name, implementationClass) {
}
}, reason => {
this.toggleLoading_(false, /* cleanup */ true);
return Promise.reject(reason);
throw reason;
});
};

Expand Down
10 changes: 3 additions & 7 deletions src/service/resources-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -1781,17 +1781,13 @@ export class Resource {
if (this.state_ == ResourceState_.LAYOUT_COMPLETE ||
this.state_ == ResourceState_.LAYOUT_FAILED ||
this.layoutCount_ > 0) {
return Promise.resolve();
return;
}
if (!this.isDisplayed()) {
return Promise.resolve();
return;
}
this.layoutCount_++;
try {
return this.element.layoutCallback();
} catch (e) {
return Promise.reject(e);
}
return this.element.layoutCallback();
});
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ export class Timer {
if (timerKey != -1) {
this.cancel(timerKey);
}
return Promise.reject(error);
throw error;
});
}

Expand Down Expand Up @@ -148,7 +148,7 @@ export class Timer {
if (timerKey != -1) {
this.cancel(timerKey);
}
return Promise.reject(error);
throw error;
});
if (!opt_racePromise) {
return delayPromise;
Expand Down
4 changes: 2 additions & 2 deletions src/url-replacements.js
Original file line number Diff line number Diff line change
Expand Up @@ -321,8 +321,8 @@ class UrlReplacements {
return loadPromise(this.win_).then(() => {
metric = timingInfo[endEvent] - timingInfo[startEvent];
return (isNaN(metric) || metric == Infinity || metric < 0)
? Promise.resolve()
: Promise.resolve(String(metric));
? undefined
: String(metric);
});
} else {
return Promise.resolve(String(metric));
Expand Down

0 comments on commit e75c9f2

Please sign in to comment.