Skip to content

Commit

Permalink
perf(do): remove tryCatch/errorObject use, 104k -> 263k ops/sec impro…
Browse files Browse the repository at this point in the history
…vement
  • Loading branch information
benlesh committed Jan 27, 2016
1 parent acdc2f5 commit ccba39d
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/operator/do.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ import {Observer} from '../Observer';
import {Subscriber} from '../Subscriber';

import {noop} from '../util/noop';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';
import {Observable} from '../Observable';

/**
Expand Down Expand Up @@ -58,30 +56,35 @@ class DoSubscriber<T> extends Subscriber<T> {
this.__complete = complete;
}

protected _next(x: T) {
const result = tryCatch(this.__next)(x);
if (result === errorObject) {
this.destination.error(errorObject.e);
} else {
this.destination.next(x);
// NOTE: important, all try catch blocks below are there for performance
// reasons. tryCatcher approach does not benefit this operator.
protected _next(value: T) {
try {
this.__next(value);
} catch (err) {
this.destination.error(err);
return;
}
this.destination.next(value);
}

protected _error(e: any) {
const result = tryCatch(this.__error)(e);
if (result === errorObject) {
this.destination.error(errorObject.e);
} else {
this.destination.error(e);
protected _error(err: any) {
try {
this.__error(err);
} catch (err) {
this.destination.error(err);
return;
}
this.destination.error(err);
}

protected _complete() {
const result = tryCatch(this.__complete)();
if (result === errorObject) {
this.destination.error(errorObject.e);
} else {
this.destination.complete();
try {
this.__complete();
} catch (err) {
this.destination.error(err);
return;
}
this.destination.complete();
}
}

0 comments on commit ccba39d

Please sign in to comment.