From 086c4bfcffa0f8e8905ed321f62dad3556a23cad Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 26 Jan 2016 12:52:36 -0800 Subject: [PATCH] perf(filter): remove tryCatch/errorObject for 2x perf improvement --- src/operator/filter.ts | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/operator/filter.ts b/src/operator/filter.ts index 7cdee8fd37..67709de1db 100644 --- a/src/operator/filter.ts +++ b/src/operator/filter.ts @@ -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'; /** @@ -35,12 +33,17 @@ class FilterSubscriber extends Subscriber { 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); } } }