From e0c153a2aef1bed7a32a2ad10a6d8574cbb1e7db Mon Sep 17 00:00:00 2001 From: Tylor Steinberger Date: Thu, 14 Apr 2016 05:58:11 -0400 Subject: [PATCH] perf(core): have FilterMapOperator extend MapOperator They seem to now share the same hidden classes and is now about 2.5x faster in the filter-map-fusion perf test --- src/core.ts | 39 ++++++--------------------------------- 1 file changed, 6 insertions(+), 33 deletions(-) diff --git a/src/core.ts b/src/core.ts index 2915799..e24296c 100644 --- a/src/core.ts +++ b/src/core.ts @@ -807,7 +807,7 @@ class MapFlattenOperator implements InternalProducer, InternalListener } class MapOperator implements Operator { - private out: Stream = null; + protected out: Stream = null; constructor(public project: (t: T) => R, public ins: Stream) { @@ -840,45 +840,18 @@ class MapOperator implements Operator { } } -class FilterMapOperator implements Operator { - private out: Stream = null; - +class FilterMapOperator extends MapOperator { constructor(public predicate: (t: T) => boolean, - public project: (t: T) => R, - public ins: Stream) { - } - - _start(out: Stream): void { - this.out = out; - this.ins._add(this); - } - - _stop(): void { - this.ins._remove(this); - this.out = null; - } - - _tryCatch(v: T) { - try { - this.out._n(this.project(v)); - } catch (e) { - this.out._e(e); - } + project: (t: T) => R, + ins: Stream) { + super(project, ins); } _n(v: T) { if (this.predicate(v)) { - this._tryCatch(v); + super._n(v); }; } - - _e(e: any) { - this.out._e(e); - } - - _c() { - this.out._c(); - } } class MapToOperator implements Operator {