Skip to content

Commit

Permalink
perf(every): remove tryCatch/errorObject (~1.8x improvement)
Browse files Browse the repository at this point in the history
Before:
                                   |       RxJS 4.0.7 | RxJS 5.0.0-beta.1 | factor | % improved
------------------------------------------------------------------------------------------------
 every-predicate-array - immediate |  94,171 (±0.40%) |  294,037 (±0.33%) |  3.12x |     212.2%
every-predicate-scalar - immediate | 112,027 (±0.59%) |  731,953 (±0.38%) |  6.53x |     553.4%
  every-predicate-this - immediate |  41,073 (±0.43%) |  160,923 (±0.38%) |  3.92x |     291.8%
       every-predicate - immediate |  44,075 (±0.43%) |  159,303 (±0.37%) |  3.61x |     261.4%

After:
                                   |       RxJS 4.0.7 | RxJS 5.0.0-beta.1 | factor | % improved
------------------------------------------------------------------------------------------------
 every-predicate-array - immediate |  91,414 (±0.91%) |  418,446 (±0.31%) |  4.58x |     357.8%
every-predicate-scalar - immediate | 112,075 (±1.06%) |  907,408 (±0.19%) |  8.10x |     709.6%
  every-predicate-this - immediate |  42,068 (±0.42%) |  295,388 (±0.23%) |  7.02x |     602.2%
       every-predicate - immediate |  44,054 (±0.39%) |  285,513 (±0.24%) |  6.48x |     548.1%
  • Loading branch information
luisgabriel authored and benlesh committed Feb 10, 2016
1 parent 74c2c44 commit 14afeb6
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/operator/every.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import {Operator} from '../Operator';
import {Observer} from '../Observer';
import {Observable} from '../Observable';
import {Subscriber} from '../Subscriber';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';

/**
* Returns an Observable that emits whether or not every item of the source satisfies the condition specified.
Expand Down Expand Up @@ -36,6 +34,7 @@ class EverySubscriber<T, R> extends Subscriber<T> {
private thisArg: any,
private source?: Observable<T>) {
super(destination);
this.thisArg = thisArg || this;
}

private notifyComplete(everyValueMatch: boolean): void {
Expand All @@ -44,11 +43,15 @@ class EverySubscriber<T, R> extends Subscriber<T> {
}

protected _next(value: T): void {
const result = tryCatch(this.predicate).call(this.thisArg || this, value, this.index++, this.source);
let result = false;
try {
result = this.predicate.call(this.thisArg, value, this.index++, this.source);
} catch (err) {
this.destination.error(err);
return;
}

if (result === errorObject) {
this.destination.error(result.e);
} else if (!result) {
if (!result) {
this.notifyComplete(false);
}
}
Expand Down

0 comments on commit 14afeb6

Please sign in to comment.