From 231f729f92292c18617743afe8d76898926db5a2 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Mon, 25 Jan 2016 17:31:49 -0800 Subject: [PATCH] perf(map): 2x increase from removing tryCatch/errorObject --- src/operator/map.ts | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/src/operator/map.ts b/src/operator/map.ts index 525001230a..17babc0d57 100644 --- a/src/operator/map.ts +++ b/src/operator/map.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'; /** * Similar to the well known `Array.prototype.map` function, this operator @@ -32,19 +30,23 @@ class MapOperator implements Operator { class MapSubscriber extends Subscriber { count: number = 0; + private thisArg: any; constructor(destination: Subscriber, private project: (value: T, index: number) => R, - private thisArg: any) { + thisArg: any) { super(destination); + this.thisArg = thisArg || this; } - protected _next(x: T) { - const result = tryCatch(this.project).call(this.thisArg || this, x, this.count++); - if (result === errorObject) { - this.error(errorObject.e); - } else { - this.destination.next(result); + next(value: T) { + let result: any; + try { + result = this.project.call(this.thisArg, value, this.count++); + } catch (err) { + this.destination.error(err); + return; } + this.destination.next(result); } }