Skip to content
This repository was archived by the owner on Apr 20, 2018. It is now read-only.

Commit e78f21d

Browse files
Perf for pairwise and partition
1 parent 34967af commit e78f21d

18 files changed

Lines changed: 260 additions & 114 deletions

dist/rx.all.compat.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8885,28 +8885,50 @@ Observable.fromNodeCallback = function (fn, ctx, selector) {
88858885
}, source);
88868886
}
88878887

8888+
var PairwiseObservable = (function (__super__) {
8889+
inherits(PairwiseObservable, __super__);
8890+
function PairwiseObservable(source) {
8891+
this.source = source;
8892+
__super__.call(this);
8893+
}
8894+
8895+
PairwiseObservable.prototype.subscribeCore = function (o) {
8896+
return this.source.subscribe(new PairwiseObserver(o));
8897+
};
8898+
8899+
return PairwiseObservable;
8900+
}(ObservableBase));
8901+
8902+
var PairwiseObserver = (function(__super__) {
8903+
inherits(PairwiseObserver, __super__);
8904+
function PairwiseObserver(o) {
8905+
this._o = o;
8906+
this._p = null;
8907+
this._hp = false;
8908+
}
8909+
8910+
PairwiseObserver.prototype.next = function (x) {
8911+
if (this._hp) {
8912+
this._o.onNext([this._p, x]);
8913+
} else {
8914+
this._hp = true;
8915+
}
8916+
this._p = x;
8917+
};
8918+
PairwiseObserver.prototype.error = function (err) { this._o.onError(err); };
8919+
PairwiseObserver.prototype.completed = function () { this._o.onCompleted(); };
8920+
8921+
return PairwiseObserver;
8922+
}(AbstractObserver));
8923+
88888924
/**
88898925
* Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
88908926
* The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
88918927
* The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
88928928
* @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
88938929
*/
88948930
observableProto.pairwise = function () {
8895-
var source = this;
8896-
return new AnonymousObservable(function (observer) {
8897-
var previous, hasPrevious = false;
8898-
return source.subscribe(
8899-
function (x) {
8900-
if (hasPrevious) {
8901-
observer.onNext([previous, x]);
8902-
} else {
8903-
hasPrevious = true;
8904-
}
8905-
previous = x;
8906-
},
8907-
observer.onError.bind(observer),
8908-
observer.onCompleted.bind(observer));
8909-
}, source);
8931+
return new PairwiseObservable(this);
89108932
};
89118933

89128934
/**
@@ -8923,9 +8945,10 @@ Observable.fromNodeCallback = function (fn, ctx, selector) {
89238945
* and the second triggers when the predicate returns false.
89248946
*/
89258947
observableProto.partition = function(predicate, thisArg) {
8948+
var fn = bindCallback(predicate, thisArg, 3);
89268949
return [
89278950
this.filter(predicate, thisArg),
8928-
this.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
8951+
this.filter(function (x, i, o) { return !fn(x, i, o); })
89298952
];
89308953
};
89318954

dist/rx.all.compat.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.compat.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.js

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8606,28 +8606,50 @@ Observable.fromNodeCallback = function (fn, ctx, selector) {
86068606
}, source);
86078607
}
86088608

8609+
var PairwiseObservable = (function (__super__) {
8610+
inherits(PairwiseObservable, __super__);
8611+
function PairwiseObservable(source) {
8612+
this.source = source;
8613+
__super__.call(this);
8614+
}
8615+
8616+
PairwiseObservable.prototype.subscribeCore = function (o) {
8617+
return this.source.subscribe(new PairwiseObserver(o));
8618+
};
8619+
8620+
return PairwiseObservable;
8621+
}(ObservableBase));
8622+
8623+
var PairwiseObserver = (function(__super__) {
8624+
inherits(PairwiseObserver, __super__);
8625+
function PairwiseObserver(o) {
8626+
this._o = o;
8627+
this._p = null;
8628+
this._hp = false;
8629+
}
8630+
8631+
PairwiseObserver.prototype.next = function (x) {
8632+
if (this._hp) {
8633+
this._o.onNext([this._p, x]);
8634+
} else {
8635+
this._hp = true;
8636+
}
8637+
this._p = x;
8638+
};
8639+
PairwiseObserver.prototype.error = function (err) { this._o.onError(err); };
8640+
PairwiseObserver.prototype.completed = function () { this._o.onCompleted(); };
8641+
8642+
return PairwiseObserver;
8643+
}(AbstractObserver));
8644+
86098645
/**
86108646
* Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
86118647
* The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
86128648
* The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
86138649
* @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
86148650
*/
86158651
observableProto.pairwise = function () {
8616-
var source = this;
8617-
return new AnonymousObservable(function (observer) {
8618-
var previous, hasPrevious = false;
8619-
return source.subscribe(
8620-
function (x) {
8621-
if (hasPrevious) {
8622-
observer.onNext([previous, x]);
8623-
} else {
8624-
hasPrevious = true;
8625-
}
8626-
previous = x;
8627-
},
8628-
observer.onError.bind(observer),
8629-
observer.onCompleted.bind(observer));
8630-
}, source);
8652+
return new PairwiseObservable(this);
86318653
};
86328654

86338655
/**
@@ -8644,9 +8666,10 @@ Observable.fromNodeCallback = function (fn, ctx, selector) {
86448666
* and the second triggers when the predicate returns false.
86458667
*/
86468668
observableProto.partition = function(predicate, thisArg) {
8669+
var fn = bindCallback(predicate, thisArg, 3);
86478670
return [
86488671
this.filter(predicate, thisArg),
8649-
this.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
8672+
this.filter(function (x, i, o) { return !fn(x, i, o); })
86508673
];
86518674
};
86528675

dist/rx.all.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.all.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/rx.coincidence.js

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333

3434
var Observable = Rx.Observable,
3535
ObservableBase = Rx.ObservableBase,
36+
AbstractObserver = Rx.internals.AbstractObserver,
3637
CompositeDisposable = Rx.CompositeDisposable,
3738
BinaryDisposable = Rx.BinaryDisposable,
3839
RefCountDisposable = Rx.RefCountDisposable,
@@ -45,6 +46,7 @@
4546
AnonymousObservable = Rx.AnonymousObservable,
4647
addRef = Rx.internals.addRef,
4748
inherits = Rx.internals.inherits,
49+
bindCallback = Rx.internals.bindCallback,
4850
noop = Rx.helpers.noop,
4951
isPromise = Rx.helpers.isPromise,
5052
isFunction = Rx.helpers.isFunction,
@@ -415,28 +417,50 @@
415417
}, source);
416418
}
417419

420+
var PairwiseObservable = (function (__super__) {
421+
inherits(PairwiseObservable, __super__);
422+
function PairwiseObservable(source) {
423+
this.source = source;
424+
__super__.call(this);
425+
}
426+
427+
PairwiseObservable.prototype.subscribeCore = function (o) {
428+
return this.source.subscribe(new PairwiseObserver(o));
429+
};
430+
431+
return PairwiseObservable;
432+
}(ObservableBase));
433+
434+
var PairwiseObserver = (function(__super__) {
435+
inherits(PairwiseObserver, __super__);
436+
function PairwiseObserver(o) {
437+
this._o = o;
438+
this._p = null;
439+
this._hp = false;
440+
}
441+
442+
PairwiseObserver.prototype.next = function (x) {
443+
if (this._hp) {
444+
this._o.onNext([this._p, x]);
445+
} else {
446+
this._hp = true;
447+
}
448+
this._p = x;
449+
};
450+
PairwiseObserver.prototype.error = function (err) { this._o.onError(err); };
451+
PairwiseObserver.prototype.completed = function () { this._o.onCompleted(); };
452+
453+
return PairwiseObserver;
454+
}(AbstractObserver));
455+
418456
/**
419457
* Returns a new observable that triggers on the second and subsequent triggerings of the input observable.
420458
* The Nth triggering of the input observable passes the arguments from the N-1th and Nth triggering as a pair.
421459
* The argument passed to the N-1th triggering is held in hidden internal state until the Nth triggering occurs.
422460
* @returns {Observable} An observable that triggers on successive pairs of observations from the input observable as an array.
423461
*/
424462
observableProto.pairwise = function () {
425-
var source = this;
426-
return new AnonymousObservable(function (observer) {
427-
var previous, hasPrevious = false;
428-
return source.subscribe(
429-
function (x) {
430-
if (hasPrevious) {
431-
observer.onNext([previous, x]);
432-
} else {
433-
hasPrevious = true;
434-
}
435-
previous = x;
436-
},
437-
observer.onError.bind(observer),
438-
observer.onCompleted.bind(observer));
439-
}, source);
463+
return new PairwiseObservable(this);
440464
};
441465

442466
/**
@@ -453,9 +477,10 @@
453477
* and the second triggers when the predicate returns false.
454478
*/
455479
observableProto.partition = function(predicate, thisArg) {
480+
var fn = bindCallback(predicate, thisArg, 3);
456481
return [
457482
this.filter(predicate, thisArg),
458-
this.filter(function (x, i, o) { return !predicate.call(thisArg, x, i, o); })
483+
this.filter(function (x, i, o) { return !fn(x, i, o); })
459484
];
460485
};
461486

dist/rx.coincidence.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)