Skip to content

Commit

Permalink
perf(filter): remove tryCatch/errorObject for 2x perf improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Jan 27, 2016
1 parent a1b0e52 commit 086c4bf
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions src/operator/filter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
import {Observable} from '../Observable';

/**
Expand Down Expand Up @@ -35,12 +33,17 @@ class FilterSubscriber<T> extends Subscriber<T> {
this.select = select;
}

protected _next(x: T) {
const result = tryCatch(this.select).call(this.thisArg || this, x, this.count++);
if (result === errorObject) {
this.destination.error(errorObject.e);
} else if (Boolean(result)) {
this.destination.next(x);
// the try catch block below is left specifically for
// optimization and perf reasons. a tryCatcher is not necessary here.
next(value: T) {
let result: any;
try {
result = this.select.call(this.thisArg, value, this.count++);
} catch (err) {
this.destination.error(err);
}
if (result) {
this.destination.next(value);
}
}
}

0 comments on commit 086c4bf

Please sign in to comment.