Skip to content

Commit 086c4bf

Browse files
committed
perf(filter): remove tryCatch/errorObject for 2x perf improvement
1 parent a1b0e52 commit 086c4bf

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/operator/filter.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import {Operator} from '../Operator';
22
import {Subscriber} from '../Subscriber';
3-
import {tryCatch} from '../util/tryCatch';
4-
import {errorObject} from '../util/errorObject';
53
import {Observable} from '../Observable';
64

75
/**
@@ -35,12 +33,17 @@ class FilterSubscriber<T> extends Subscriber<T> {
3533
this.select = select;
3634
}
3735

38-
protected _next(x: T) {
39-
const result = tryCatch(this.select).call(this.thisArg || this, x, this.count++);
40-
if (result === errorObject) {
41-
this.destination.error(errorObject.e);
42-
} else if (Boolean(result)) {
43-
this.destination.next(x);
36+
// the try catch block below is left specifically for
37+
// optimization and perf reasons. a tryCatcher is not necessary here.
38+
next(value: T) {
39+
let result: any;
40+
try {
41+
result = this.select.call(this.thisArg, value, this.count++);
42+
} catch (err) {
43+
this.destination.error(err);
44+
}
45+
if (result) {
46+
this.destination.next(value);
4447
}
4548
}
4649
}

0 commit comments

Comments
 (0)