Skip to content

Commit

Permalink
perf(withLatestFrom): remove tryCatch/errorObject, 92k -> 107k (16% i…
Browse files Browse the repository at this point in the history
…mprovement)
  • Loading branch information
benlesh committed Jan 27, 2016
1 parent 359ccae commit e4ccb44
Showing 1 changed file with 15 additions and 14 deletions.
29 changes: 15 additions & 14 deletions src/operator/withLatestFrom.ts
Original file line number Diff line number Diff line change
@@ -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';
import {OuterSubscriber} from '../OuterSubscriber';
import {subscribeToResult} from '../util/subscribeToResult';

Expand Down Expand Up @@ -81,20 +79,23 @@ class WithLatestFromSubscriber<T, R> extends OuterSubscriber<T, R> {

protected _next(value: T) {
if (this.toRespond.length === 0) {
const values = this.values;
const destination = this.destination;
const project = this.project;
const args = [value, ...values];
if (project) {
let result = tryCatch(this.project).apply(this, args);
if (result === errorObject) {
destination.error(result.e);
} else {
destination.next(result);
}
const args = [value, ...this.values];
if (this.project) {
this._tryProject(args);
} else {
destination.next(args);
this.destination.next(args);
}
}
}

private _tryProject(args: any[]) {
let result: any;
try {
result = this.project.apply(this, args);
} catch (err) {
this.destination.error(err);
return;
}
this.destination.next(result);
}
}

0 comments on commit e4ccb44

Please sign in to comment.