Skip to content

Commit

Permalink
perf(skipWhile): remove tryCatch/errorObject (~1.6x 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
----------------------------------------------------------------------------------
skipwhile - immediate | 27,101 (±1.37%) |  122,827 (±0.29%) |  4.53x |     353.2%
            skipwhile |  8,034 (±1.32%) |   82,160 (±0.28%) | 10.23x |     922.7%

After:
                      |      RxJS 4.0.7 | RxJS 5.0.0-beta.1 | factor | % improved
----------------------------------------------------------------------------------
skipwhile - immediate | 27,040 (±0.30%) |  197,417 (±0.28%) |  7.30x |     630.1%
            skipwhile |  8,842 (±2.08%) |  112,757 (±0.55%) | 12.75x |   1,175.2%
  • Loading branch information
luisgabriel authored and kwonoj committed Feb 4, 2016
1 parent a8f4678 commit cf002db
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions src/operator/skipWhile.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import {Observable} from '../Observable';
import {Operator} from '../Operator';
import {Subscriber} from '../Subscriber';
import {tryCatch} from '../util/tryCatch';
import {errorObject} from '../util/errorObject';

/**
* Returns an Observable that skips all items emitted by the source Observable as long as a specified condition holds
Expand Down Expand Up @@ -38,17 +36,21 @@ class SkipWhileSubscriber<T> extends Subscriber<T> {

protected _next(value: T): void {
const destination = this.destination;
if (this.skipping === true) {
const index = this.index++;
const result = tryCatch(this.predicate)(value, index);
if (result === errorObject) {
destination.error(errorObject.e);
} else {
this.skipping = Boolean(result);
}
if (this.skipping) {
this.tryCallPredicate(value);
}
if (this.skipping === false) {

if (!this.skipping) {
destination.next(value);
}
}

private tryCallPredicate(value: T): void {
try {
const result = this.predicate(value, this.index++);
this.skipping = Boolean(result);
} catch (err) {
this.destination.error(err);
}
}
}

0 comments on commit cf002db

Please sign in to comment.