Skip to content

Commit

Permalink
perf(scan): remove tryCatch/errorObject for custom tryCatcher 1.75x i…
Browse files Browse the repository at this point in the history
…mprovement
  • Loading branch information
benlesh committed Jan 27, 2016
1 parent 086c4bf commit 338135d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/operator/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class FilterSubscriber<T> extends Subscriber<T> {
result = this.select.call(this.thisArg, value, this.count++);
} catch (err) {
this.destination.error(err);
return;
}
if (result) {
this.destination.next(value);
Expand Down
23 changes: 13 additions & 10 deletions src/operator/scan.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -49,18 +47,23 @@ class ScanSubscriber<T, R> extends Subscriber<T> {
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(<R>this.seed, value);
} catch (err) {
this.destination.error(err);
}
this.seed = result;
this.destination.next(result);
}
}

0 comments on commit 338135d

Please sign in to comment.