Skip to content

Commit 338135d

Browse files
committed
perf(scan): remove tryCatch/errorObject for custom tryCatcher 1.75x improvement
1 parent 086c4bf commit 338135d

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/operator/filter.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class FilterSubscriber<T> extends Subscriber<T> {
4141
result = this.select.call(this.thisArg, value, this.count++);
4242
} catch (err) {
4343
this.destination.error(err);
44+
return;
4445
}
4546
if (result) {
4647
this.destination.next(value);

src/operator/scan.ts

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {Operator} from '../Operator';
22
import {Observable} from '../Observable';
33
import {Subscriber} from '../Subscriber';
4-
import {tryCatch} from '../util/tryCatch';
5-
import {errorObject} from '../util/errorObject';
64

75
/**
86
* Returns an Observable that applies a specified accumulator function to each item emitted by the source Observable.
@@ -49,18 +47,23 @@ class ScanSubscriber<T, R> extends Subscriber<T> {
4947
this.accumulatorSet = typeof seed !== 'undefined';
5048
}
5149

52-
protected _next(value: T): void {
50+
next(value: T): void {
5351
if (!this.accumulatorSet) {
5452
this.seed = value;
5553
this.destination.next(value);
5654
} else {
57-
const result = tryCatch(this.accumulator).call(this, this.seed, value);
58-
if (result === errorObject) {
59-
this.destination.error(errorObject.e);
60-
} else {
61-
this.seed = result;
62-
this.destination.next(this.seed);
63-
}
55+
return this._tryNext(value);
6456
}
6557
}
58+
59+
private _tryNext(value: T): void {
60+
let result: any;
61+
try {
62+
result = this.accumulator(<R>this.seed, value);
63+
} catch (err) {
64+
this.destination.error(err);
65+
}
66+
this.seed = result;
67+
this.destination.next(result);
68+
}
6669
}

0 commit comments

Comments
 (0)