Skip to content

Commit ccba39d

Browse files
committed
perf(do): remove tryCatch/errorObject use, 104k -> 263k ops/sec improvement
1 parent acdc2f5 commit ccba39d

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

src/operator/do.ts

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,6 @@ import {Observer} from '../Observer';
33
import {Subscriber} from '../Subscriber';
44

55
import {noop} from '../util/noop';
6-
import {tryCatch} from '../util/tryCatch';
7-
import {errorObject} from '../util/errorObject';
86
import {Observable} from '../Observable';
97

108
/**
@@ -58,30 +56,35 @@ class DoSubscriber<T> extends Subscriber<T> {
5856
this.__complete = complete;
5957
}
6058

61-
protected _next(x: T) {
62-
const result = tryCatch(this.__next)(x);
63-
if (result === errorObject) {
64-
this.destination.error(errorObject.e);
65-
} else {
66-
this.destination.next(x);
59+
// NOTE: important, all try catch blocks below are there for performance
60+
// reasons. tryCatcher approach does not benefit this operator.
61+
protected _next(value: T) {
62+
try {
63+
this.__next(value);
64+
} catch (err) {
65+
this.destination.error(err);
66+
return;
6767
}
68+
this.destination.next(value);
6869
}
6970

70-
protected _error(e: any) {
71-
const result = tryCatch(this.__error)(e);
72-
if (result === errorObject) {
73-
this.destination.error(errorObject.e);
74-
} else {
75-
this.destination.error(e);
71+
protected _error(err: any) {
72+
try {
73+
this.__error(err);
74+
} catch (err) {
75+
this.destination.error(err);
76+
return;
7677
}
78+
this.destination.error(err);
7779
}
7880

7981
protected _complete() {
80-
const result = tryCatch(this.__complete)();
81-
if (result === errorObject) {
82-
this.destination.error(errorObject.e);
83-
} else {
84-
this.destination.complete();
82+
try {
83+
this.__complete();
84+
} catch (err) {
85+
this.destination.error(err);
86+
return;
8587
}
88+
this.destination.complete();
8689
}
8790
}

0 commit comments

Comments
 (0)