Skip to content

Commit

Permalink
perf(map): 2x increase from removing tryCatch/errorObject
Browse files Browse the repository at this point in the history
  • Loading branch information
benlesh committed Jan 27, 2016
1 parent 6f53dbf commit 231f729
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/operator/map.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';

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

class MapSubscriber<T, R> extends Subscriber<T> {
count: number = 0;
private thisArg: any;

constructor(destination: Subscriber<R>,
private project: (value: T, index: number) => R,
private thisArg: any) {
thisArg: any) {
super(destination);
this.thisArg = thisArg || this;
}

protected _next(x: T) {
const result = tryCatch(this.project).call(this.thisArg || this, x, this.count++);
if (result === errorObject) {
this.error(errorObject.e);
} else {
this.destination.next(result);
next(value: T) {
let result: any;
try {
result = this.project.call(this.thisArg, value, this.count++);
} catch (err) {
this.destination.error(err);
return;
}
this.destination.next(result);
}
}

0 comments on commit 231f729

Please sign in to comment.