From e4ccb444305b5b5e0ec20c1a3a024f3904eb1341 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 26 Jan 2016 20:46:57 -0800 Subject: [PATCH] perf(withLatestFrom): remove tryCatch/errorObject, 92k -> 107k (16% improvement) --- src/operator/withLatestFrom.ts | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/operator/withLatestFrom.ts b/src/operator/withLatestFrom.ts index 196dcfd612..cdc5d89d5e 100644 --- a/src/operator/withLatestFrom.ts +++ b/src/operator/withLatestFrom.ts @@ -1,8 +1,6 @@ import {Operator} from '../Operator'; import {Subscriber} from '../Subscriber'; import {Observable} from '../Observable'; -import {tryCatch} from '../util/tryCatch'; -import {errorObject} from '../util/errorObject'; import {OuterSubscriber} from '../OuterSubscriber'; import {subscribeToResult} from '../util/subscribeToResult'; @@ -81,20 +79,23 @@ class WithLatestFromSubscriber extends OuterSubscriber { protected _next(value: T) { if (this.toRespond.length === 0) { - const values = this.values; - const destination = this.destination; - const project = this.project; - const args = [value, ...values]; - if (project) { - let result = tryCatch(this.project).apply(this, args); - if (result === errorObject) { - destination.error(result.e); - } else { - destination.next(result); - } + const args = [value, ...this.values]; + if (this.project) { + this._tryProject(args); } else { - destination.next(args); + this.destination.next(args); } } } + + private _tryProject(args: any[]) { + let result: any; + try { + result = this.project.apply(this, args); + } catch (err) { + this.destination.error(err); + return; + } + this.destination.next(result); + } }