From 338135d8512ca5154ee1ad42a931e35cca7321f7 Mon Sep 17 00:00:00 2001 From: Ben Lesh Date: Tue, 26 Jan 2016 13:00:00 -0800 Subject: [PATCH] perf(scan): remove tryCatch/errorObject for custom tryCatcher 1.75x improvement --- src/operator/filter.ts | 1 + src/operator/scan.ts | 23 +++++++++++++---------- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/operator/filter.ts b/src/operator/filter.ts index 67709de1db..8f429c6587 100644 --- a/src/operator/filter.ts +++ b/src/operator/filter.ts @@ -41,6 +41,7 @@ class FilterSubscriber extends Subscriber { result = this.select.call(this.thisArg, value, this.count++); } catch (err) { this.destination.error(err); + return; } if (result) { this.destination.next(value); diff --git a/src/operator/scan.ts b/src/operator/scan.ts index f60b70586a..e1c2a6cde9 100644 --- a/src/operator/scan.ts +++ b/src/operator/scan.ts @@ -1,8 +1,6 @@ import {Operator} from '../Operator'; import {Observable} from '../Observable'; import {Subscriber} from '../Subscriber'; -import {tryCatch} from '../util/tryCatch'; -import {errorObject} from '../util/errorObject'; /** * Returns an Observable that applies a specified accumulator function to each item emitted by the source Observable. @@ -49,18 +47,23 @@ class ScanSubscriber extends Subscriber { this.accumulatorSet = typeof seed !== 'undefined'; } - protected _next(value: T): void { + next(value: T): void { if (!this.accumulatorSet) { this.seed = value; this.destination.next(value); } else { - const result = tryCatch(this.accumulator).call(this, this.seed, value); - if (result === errorObject) { - this.destination.error(errorObject.e); - } else { - this.seed = result; - this.destination.next(this.seed); - } + return this._tryNext(value); } } + + private _tryNext(value: T): void { + let result: any; + try { + result = this.accumulator(this.seed, value); + } catch (err) { + this.destination.error(err); + } + this.seed = result; + this.destination.next(result); + } }