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

Commit 0eb0912

Browse files
Perf for catch
1 parent 8c398fd commit 0eb0912

25 files changed

Lines changed: 424 additions & 155 deletions

dist/rx.all.compat.js

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,11 +2309,16 @@
23092309
Enumerable.prototype.concat = function () {
23102310
return new ConcatObservable(this);
23112311
};
2312-
2313-
Enumerable.prototype.catchError = function () {
2314-
var sources = this;
2315-
return new AnonymousObservable(function (o) {
2316-
var e = sources[$iterator$]();
2312+
2313+
var CatchErrorObservable = (function(__super__) {
2314+
inherits(CatchErrorObservable, __super__);
2315+
function CatchErrorObservable(sources) {
2316+
this.sources = sources;
2317+
__super__.call(this);
2318+
}
2319+
2320+
CatchErrorObservable.prototype.subscribeCore = function (o) {
2321+
var e = this.sources[$iterator$]();
23172322

23182323
var isDisposed, subscription = new SerialDisposable();
23192324
var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
@@ -2322,12 +2327,7 @@
23222327
if (currentItem === errorObj) { return o.onError(currentItem.e); }
23232328

23242329
if (currentItem.done) {
2325-
if (lastException !== null) {
2326-
o.onError(lastException);
2327-
} else {
2328-
o.onCompleted();
2329-
}
2330-
return;
2330+
return lastException !== null ? o.onError(lastException) : o.onCompleted();
23312331
}
23322332

23332333
// Check if promise
@@ -2344,9 +2344,42 @@
23442344
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
23452345
isDisposed = true;
23462346
}));
2347-
});
2348-
};
2347+
};
2348+
2349+
function InnerObserver(o, s) {
2350+
this.o = o;
2351+
this.s = s;
2352+
this.isStopped = false;
2353+
}
2354+
InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.o.onNext(x); } };
2355+
InnerObserver.prototype.onError = function (err) {
2356+
if (!this.isStopped) {
2357+
this.isStopped = true;
2358+
this.s(err);
2359+
}
2360+
};
2361+
InnerObserver.prototype.onCompleted = function () {
2362+
if (!this.isStopped) {
2363+
this.isStopped = true;
2364+
this.onCompleted();
2365+
}
2366+
};
2367+
InnerObserver.prototype.dispose = function () { this.isStopped = true; };
2368+
InnerObserver.prototype.fail = function (err) {
2369+
if (!this.isStopped) {
2370+
this.isStopped = true
2371+
this.o.onError(err);
2372+
return true;
2373+
}
2374+
return false;
2375+
};
2376+
2377+
return CatchErrorObservable;
2378+
}(ObservableBase));
23492379

2380+
Enumerable.prototype.catchError = function () {
2381+
return new CatchErrorObservable(this);
2382+
};
23502383

23512384
Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
23522385
var sources = this;

dist/rx.all.compat.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.compat.min.js

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.js

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,11 +2118,16 @@
21182118
Enumerable.prototype.concat = function () {
21192119
return new ConcatObservable(this);
21202120
};
2121-
2122-
Enumerable.prototype.catchError = function () {
2123-
var sources = this;
2124-
return new AnonymousObservable(function (o) {
2125-
var e = sources[$iterator$]();
2121+
2122+
var CatchErrorObservable = (function(__super__) {
2123+
inherits(CatchErrorObservable, __super__);
2124+
function CatchErrorObservable(sources) {
2125+
this.sources = sources;
2126+
__super__.call(this);
2127+
}
2128+
2129+
CatchErrorObservable.prototype.subscribeCore = function (o) {
2130+
var e = this.sources[$iterator$]();
21262131

21272132
var isDisposed, subscription = new SerialDisposable();
21282133
var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
@@ -2131,12 +2136,7 @@
21312136
if (currentItem === errorObj) { return o.onError(currentItem.e); }
21322137

21332138
if (currentItem.done) {
2134-
if (lastException !== null) {
2135-
o.onError(lastException);
2136-
} else {
2137-
o.onCompleted();
2138-
}
2139-
return;
2139+
return lastException !== null ? o.onError(lastException) : o.onCompleted();
21402140
}
21412141

21422142
// Check if promise
@@ -2153,9 +2153,42 @@
21532153
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
21542154
isDisposed = true;
21552155
}));
2156-
});
2157-
};
2156+
};
2157+
2158+
function InnerObserver(o, s) {
2159+
this.o = o;
2160+
this.s = s;
2161+
this.isStopped = false;
2162+
}
2163+
InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.o.onNext(x); } };
2164+
InnerObserver.prototype.onError = function (err) {
2165+
if (!this.isStopped) {
2166+
this.isStopped = true;
2167+
this.s(err);
2168+
}
2169+
};
2170+
InnerObserver.prototype.onCompleted = function () {
2171+
if (!this.isStopped) {
2172+
this.isStopped = true;
2173+
this.onCompleted();
2174+
}
2175+
};
2176+
InnerObserver.prototype.dispose = function () { this.isStopped = true; };
2177+
InnerObserver.prototype.fail = function (err) {
2178+
if (!this.isStopped) {
2179+
this.isStopped = true
2180+
this.o.onError(err);
2181+
return true;
2182+
}
2183+
return false;
2184+
};
2185+
2186+
return CatchErrorObservable;
2187+
}(ObservableBase));
21582188

2189+
Enumerable.prototype.catchError = function () {
2190+
return new CatchErrorObservable(this);
2191+
};
21592192

21602193
Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
21612194
var sources = this;

dist/rx.all.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.min.js

Lines changed: 6 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.compat.js

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2309,11 +2309,16 @@
23092309
Enumerable.prototype.concat = function () {
23102310
return new ConcatObservable(this);
23112311
};
2312-
2313-
Enumerable.prototype.catchError = function () {
2314-
var sources = this;
2315-
return new AnonymousObservable(function (o) {
2316-
var e = sources[$iterator$]();
2312+
2313+
var CatchErrorObservable = (function(__super__) {
2314+
inherits(CatchErrorObservable, __super__);
2315+
function CatchErrorObservable(sources) {
2316+
this.sources = sources;
2317+
__super__.call(this);
2318+
}
2319+
2320+
CatchErrorObservable.prototype.subscribeCore = function (o) {
2321+
var e = this.sources[$iterator$]();
23172322

23182323
var isDisposed, subscription = new SerialDisposable();
23192324
var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
@@ -2322,12 +2327,7 @@
23222327
if (currentItem === errorObj) { return o.onError(currentItem.e); }
23232328

23242329
if (currentItem.done) {
2325-
if (lastException !== null) {
2326-
o.onError(lastException);
2327-
} else {
2328-
o.onCompleted();
2329-
}
2330-
return;
2330+
return lastException !== null ? o.onError(lastException) : o.onCompleted();
23312331
}
23322332

23332333
// Check if promise
@@ -2344,9 +2344,42 @@
23442344
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
23452345
isDisposed = true;
23462346
}));
2347-
});
2348-
};
2347+
};
2348+
2349+
function InnerObserver(o, s) {
2350+
this.o = o;
2351+
this.s = s;
2352+
this.isStopped = false;
2353+
}
2354+
InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.o.onNext(x); } };
2355+
InnerObserver.prototype.onError = function (err) {
2356+
if (!this.isStopped) {
2357+
this.isStopped = true;
2358+
this.s(err);
2359+
}
2360+
};
2361+
InnerObserver.prototype.onCompleted = function () {
2362+
if (!this.isStopped) {
2363+
this.isStopped = true;
2364+
this.onCompleted();
2365+
}
2366+
};
2367+
InnerObserver.prototype.dispose = function () { this.isStopped = true; };
2368+
InnerObserver.prototype.fail = function (err) {
2369+
if (!this.isStopped) {
2370+
this.isStopped = true
2371+
this.o.onError(err);
2372+
return true;
2373+
}
2374+
return false;
2375+
};
2376+
2377+
return CatchErrorObservable;
2378+
}(ObservableBase));
23492379

2380+
Enumerable.prototype.catchError = function () {
2381+
return new CatchErrorObservable(this);
2382+
};
23502383

23512384
Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
23522385
var sources = this;

dist/rx.compat.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.compat.min.js

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.js

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2118,11 +2118,16 @@
21182118
Enumerable.prototype.concat = function () {
21192119
return new ConcatObservable(this);
21202120
};
2121-
2122-
Enumerable.prototype.catchError = function () {
2123-
var sources = this;
2124-
return new AnonymousObservable(function (o) {
2125-
var e = sources[$iterator$]();
2121+
2122+
var CatchErrorObservable = (function(__super__) {
2123+
inherits(CatchErrorObservable, __super__);
2124+
function CatchErrorObservable(sources) {
2125+
this.sources = sources;
2126+
__super__.call(this);
2127+
}
2128+
2129+
CatchErrorObservable.prototype.subscribeCore = function (o) {
2130+
var e = this.sources[$iterator$]();
21262131

21272132
var isDisposed, subscription = new SerialDisposable();
21282133
var cancelable = immediateScheduler.scheduleRecursiveWithState(null, function (lastException, self) {
@@ -2131,12 +2136,7 @@
21312136
if (currentItem === errorObj) { return o.onError(currentItem.e); }
21322137

21332138
if (currentItem.done) {
2134-
if (lastException !== null) {
2135-
o.onError(lastException);
2136-
} else {
2137-
o.onCompleted();
2138-
}
2139-
return;
2139+
return lastException !== null ? o.onError(lastException) : o.onCompleted();
21402140
}
21412141

21422142
// Check if promise
@@ -2153,9 +2153,42 @@
21532153
return new CompositeDisposable(subscription, cancelable, disposableCreate(function () {
21542154
isDisposed = true;
21552155
}));
2156-
});
2157-
};
2156+
};
2157+
2158+
function InnerObserver(o, s) {
2159+
this.o = o;
2160+
this.s = s;
2161+
this.isStopped = false;
2162+
}
2163+
InnerObserver.prototype.onNext = function (x) { if(!this.isStopped) { this.o.onNext(x); } };
2164+
InnerObserver.prototype.onError = function (err) {
2165+
if (!this.isStopped) {
2166+
this.isStopped = true;
2167+
this.s(err);
2168+
}
2169+
};
2170+
InnerObserver.prototype.onCompleted = function () {
2171+
if (!this.isStopped) {
2172+
this.isStopped = true;
2173+
this.onCompleted();
2174+
}
2175+
};
2176+
InnerObserver.prototype.dispose = function () { this.isStopped = true; };
2177+
InnerObserver.prototype.fail = function (err) {
2178+
if (!this.isStopped) {
2179+
this.isStopped = true
2180+
this.o.onError(err);
2181+
return true;
2182+
}
2183+
return false;
2184+
};
2185+
2186+
return CatchErrorObservable;
2187+
}(ObservableBase));
21582188

2189+
Enumerable.prototype.catchError = function () {
2190+
return new CatchErrorObservable(this);
2191+
};
21592192

21602193
Enumerable.prototype.catchErrorWhen = function (notificationHandler) {
21612194
var sources = this;

0 commit comments

Comments
 (0)