Skip to content

Commit 231f729

Browse files
committed
perf(map): 2x increase from removing tryCatch/errorObject
1 parent 6f53dbf commit 231f729

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

src/operator/map.ts

Lines changed: 11 additions & 9 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

75
/**
86
* Similar to the well known `Array.prototype.map` function, this operator
@@ -32,19 +30,23 @@ class MapOperator<T, R> implements Operator<T, R> {
3230

3331
class MapSubscriber<T, R> extends Subscriber<T> {
3432
count: number = 0;
33+
private thisArg: any;
3534

3635
constructor(destination: Subscriber<R>,
3736
private project: (value: T, index: number) => R,
38-
private thisArg: any) {
37+
thisArg: any) {
3938
super(destination);
39+
this.thisArg = thisArg || this;
4040
}
4141

42-
protected _next(x: T) {
43-
const result = tryCatch(this.project).call(this.thisArg || this, x, this.count++);
44-
if (result === errorObject) {
45-
this.error(errorObject.e);
46-
} else {
47-
this.destination.next(result);
42+
next(value: T) {
43+
let result: any;
44+
try {
45+
result = this.project.call(this.thisArg, value, this.count++);
46+
} catch (err) {
47+
this.destination.error(err);
48+
return;
4849
}
50+
this.destination.next(result);
4951
}
5052
}

0 commit comments

Comments
 (0)