Skip to content

Commit

Permalink
perf(core): have FilterMapOperator extend MapOperator
Browse files Browse the repository at this point in the history
They seem to now share the same hidden classes and is now about
2.5x faster in the filter-map-fusion perf test
  • Loading branch information
TylorS authored and Andre Medeiros committed Apr 14, 2016
1 parent 133c400 commit e0c153a
Showing 1 changed file with 6 additions and 33 deletions.
39 changes: 6 additions & 33 deletions src/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -807,7 +807,7 @@ class MapFlattenOperator<T> implements InternalProducer<T>, InternalListener<T>
}

class MapOperator<T, R> implements Operator<T, R> {
private out: Stream<R> = null;
protected out: Stream<R> = null;

constructor(public project: (t: T) => R,
public ins: Stream<T>) {
Expand Down Expand Up @@ -840,45 +840,18 @@ class MapOperator<T, R> implements Operator<T, R> {
}
}

class FilterMapOperator<T, R> implements Operator<T, R> {
private out: Stream<R> = null;

class FilterMapOperator<T, R> extends MapOperator<T, R> {
constructor(public predicate: (t: T) => boolean,
public project: (t: T) => R,
public ins: Stream<T>) {
}

_start(out: Stream<R>): 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<T>) {
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<T, R> implements Operator<T, R> {
Expand Down

0 comments on commit e0c153a

Please sign in to comment.