Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 6838c97

Browse files
committed
perf($q): small $q performance optimization
Only generate a new promise when `then` receives some non-undefined parameter Closes #12535
1 parent f827a8e commit 6838c97

File tree

2 files changed

+5
-0
lines changed

2 files changed

+5
-0
lines changed

lib/promises-aplus/promises-aplus-test-adapter.js

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
var isFunction = function isFunction(value){return typeof value == 'function';};
55
var isPromiseLike = function isPromiseLike(obj) {return obj && isFunction(obj.then);};
66
var isObject = function isObject(value){return value != null && typeof value === 'object';};
7+
var isUndefined = function isUndefined(value) {return typeof value === 'undefined';};
8+
79
var minErr = function minErr (module, constructor) {
810
return function (){
911
var ErrorConstructor = constructor || Error;

src/ng/q.js

+3
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,9 @@ function qFactory(nextTick, exceptionHandler) {
274274

275275
extend(Promise.prototype, {
276276
then: function(onFulfilled, onRejected, progressBack) {
277+
if (isUndefined(onFulfilled) && isUndefined(onRejected) && isUndefined(progressBack)) {
278+
return this;
279+
}
277280
var result = new Deferred();
278281

279282
this.$$state.pending = this.$$state.pending || [];

0 commit comments

Comments
 (0)