Skip to content

Commit e4ccb44

Browse files
committed
perf(withLatestFrom): remove tryCatch/errorObject, 92k -> 107k (16% improvement)
1 parent 359ccae commit e4ccb44

File tree

1 file changed

+15
-14
lines changed

1 file changed

+15
-14
lines changed

src/operator/withLatestFrom.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
import {Operator} from '../Operator';
22
import {Subscriber} from '../Subscriber';
33
import {Observable} from '../Observable';
4-
import {tryCatch} from '../util/tryCatch';
5-
import {errorObject} from '../util/errorObject';
64
import {OuterSubscriber} from '../OuterSubscriber';
75
import {subscribeToResult} from '../util/subscribeToResult';
86

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

8280
protected _next(value: T) {
8381
if (this.toRespond.length === 0) {
84-
const values = this.values;
85-
const destination = this.destination;
86-
const project = this.project;
87-
const args = [value, ...values];
88-
if (project) {
89-
let result = tryCatch(this.project).apply(this, args);
90-
if (result === errorObject) {
91-
destination.error(result.e);
92-
} else {
93-
destination.next(result);
94-
}
82+
const args = [value, ...this.values];
83+
if (this.project) {
84+
this._tryProject(args);
9585
} else {
96-
destination.next(args);
86+
this.destination.next(args);
9787
}
9888
}
9989
}
90+
91+
private _tryProject(args: any[]) {
92+
let result: any;
93+
try {
94+
result = this.project.apply(this, args);
95+
} catch (err) {
96+
this.destination.error(err);
97+
return;
98+
}
99+
this.destination.next(result);
100+
}
100101
}

0 commit comments

Comments
 (0)