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

Commit f889c4d

Browse files
Fixing take with more perf
1 parent 6b80d81 commit f889c4d

28 files changed

Lines changed: 1294 additions & 842 deletions

Gruntfile.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ module.exports = function (grunt) {
149149
'src/core/linq/observable/selectswitch.js',
150150
'src/core/linq/observable/skip.js',
151151
'src/core/linq/observable/skipwhile.js',
152-
'src/core/linq/observable/take.js',
152+
'src/core/perf/operators/take.js',
153153
'src/core/linq/observable/takewhile.js',
154154
'src/core/perf/operators/filter.js',
155155

@@ -443,7 +443,7 @@ module.exports = function (grunt) {
443443
'src/core/linq/observable/selectswitch.js',
444444
'src/core/linq/observable/skip.js',
445445
'src/core/linq/observable/skipwhile.js',
446-
'src/core/linq/observable/take.js',
446+
'src/core/perf/operators/take.js',
447447
'src/core/linq/observable/takewhile.js',
448448
'src/core/perf/operators/filter.js',
449449

@@ -735,7 +735,7 @@ module.exports = function (grunt) {
735735
'src/core/linq/observable/selectswitch.js',
736736
'src/core/linq/observable/skip.js',
737737
'src/core/linq/observable/skipwhile.js',
738-
'src/core/linq/observable/take.js',
738+
'src/core/perf/operators/take.js',
739739
'src/core/linq/observable/takewhile.js',
740740
'src/core/perf/operators/filter.js',
741741

@@ -884,7 +884,7 @@ module.exports = function (grunt) {
884884
'src/core/linq/observable/selectswitch.js',
885885
'src/core/linq/observable/skip.js',
886886
'src/core/linq/observable/skipwhile.js',
887-
'src/core/linq/observable/take.js',
887+
'src/core/perf/operators/take.js',
888888
'src/core/linq/observable/takewhile.js',
889889
'src/core/perf/operators/filter.js',
890890

@@ -1008,7 +1008,7 @@ module.exports = function (grunt) {
10081008
'src/core/linq/observable/selectswitch.js',
10091009
'src/core/linq/observable/skip.js',
10101010
'src/core/linq/observable/skipwhile.js',
1011-
'src/core/linq/observable/take.js',
1011+
'src/core/perf/operators/take.js',
10121012
'src/core/linq/observable/takewhile.js',
10131013
'src/core/perf/operators/filter.js',
10141014

@@ -1178,7 +1178,7 @@ module.exports = function (grunt) {
11781178
'src/core/linq/observable/selectswitch.js',
11791179
'src/core/linq/observable/skip.js',
11801180
'src/core/linq/observable/skipwhile.js',
1181-
'src/core/linq/observable/take.js',
1181+
'src/core/perf/operators/take.js',
11821182
'src/core/linq/observable/takewhile.js',
11831183
'src/core/perf/operators/filter.js',
11841184

dist/rx.all.compat.js

Lines changed: 143 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -3914,59 +3914,60 @@
39143914
};
39153915

39163916
var TakeUntilObservable = (function(__super__) {
3917-
inherits(TakeUntilObservable, __super__);
3918-
3919-
function TakeUntilObservable(source, other) {
3920-
this.source = source;
3921-
this.other = isPromise(other) ? observableFromPromise(other) : other;
3922-
__super__.call(this);
3923-
}
3924-
3925-
TakeUntilObservable.prototype.subscribeCore = function(o) {
3926-
return new CompositeDisposable(
3927-
this.source.subscribe(o),
3928-
this.other.subscribe(new InnerObserver(o))
3929-
);
3930-
};
3931-
3932-
function InnerObserver(o) {
3933-
this.o = o;
3934-
this.isStopped = false;
3935-
}
3936-
InnerObserver.prototype.onNext = function (x) {
3937-
if (this.isStopped) { return; }
3938-
this.o.onCompleted();
3939-
};
3940-
InnerObserver.prototype.onError = function (err) {
3941-
if (!this.isStopped) {
3942-
this.isStopped = true;
3943-
this.o.onError(err);
3944-
}
3945-
};
3946-
InnerObserver.prototype.onCompleted = function () {
3947-
!this.isStopped && (this.isStopped = true);
3948-
};
3949-
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
3950-
InnerObserver.prototype.fail = function (e) {
3951-
if (!this.isStopped) {
3952-
this.isStopped = true;
3953-
this.observer.onError(e);
3954-
return true;
3955-
}
3956-
return false;
3957-
};
3958-
3959-
return TakeUntilObservable;
3960-
}(ObservableBase));
3961-
3962-
/**
3917+
inherits(TakeUntilObservable, __super__);
3918+
3919+
function TakeUntilObservable(source, other) {
3920+
this.source = source;
3921+
this.other = isPromise(other) ? observableFromPromise(other) : other;
3922+
__super__.call(this);
3923+
}
3924+
3925+
TakeUntilObservable.prototype.subscribeCore = function(o) {
3926+
return new CompositeDisposable(
3927+
this.source.subscribe(o),
3928+
this.other.subscribe(new InnerObserver(o))
3929+
);
3930+
};
3931+
3932+
function InnerObserver(o) {
3933+
this.o = o;
3934+
this.isStopped = false;
3935+
}
3936+
InnerObserver.prototype.onNext = function (x) {
3937+
if (this.isStopped) { return; }
3938+
this.o.onCompleted();
3939+
};
3940+
InnerObserver.prototype.onError = function (err) {
3941+
if (!this.isStopped) {
3942+
this.isStopped = true;
3943+
this.o.onError(err);
3944+
}
3945+
};
3946+
InnerObserver.prototype.onCompleted = function () {
3947+
!this.isStopped && (this.isStopped = true);
3948+
};
3949+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
3950+
InnerObserver.prototype.fail = function (e) {
3951+
if (!this.isStopped) {
3952+
this.isStopped = true;
3953+
this.o.onError(e);
3954+
return true;
3955+
}
3956+
return false;
3957+
};
3958+
3959+
return TakeUntilObservable;
3960+
}(ObservableBase));
3961+
3962+
/**
39633963
* Returns the values from the source observable sequence until the other observable sequence produces a value.
39643964
* @param {Observable | Promise} other Observable sequence or Promise that terminates propagation of elements of the source sequence.
39653965
* @returns {Observable} An observable sequence containing the elements of the source sequence up to the point the other sequence interrupted further propagation.
39663966
*/
39673967
observableProto.takeUntil = function (other) {
39683968
return new TakeUntilObservable(this, other);
39693969
};
3970+
39703971
function falseFactory() { return false; }
39713972

39723973
/**
@@ -4353,50 +4354,50 @@
43534354
return this.ensure(action);
43544355
};
43554356

4356-
var IgnoreElementsObservable = (function(__super__) {
4357-
inherits(IgnoreElementsObservable, __super__);
4358-
4359-
function IgnoreElementsObservable(source) {
4360-
this.source = source;
4361-
__super__.call(this);
4362-
}
4363-
4364-
IgnoreElementsObservable.prototype.subscribeCore = function (o) {
4365-
return this.source.subscribe(new InnerObserver(o));
4366-
};
4367-
4368-
function InnerObserver(o) {
4369-
this.o = o;
4370-
this.isStopped = false;
4371-
}
4372-
InnerObserver.prototype.onNext = noop;
4373-
InnerObserver.prototype.onError = function (err) {
4374-
if(!this.isStopped) {
4375-
this.isStopped = true;
4376-
this.o.onError(err);
4377-
}
4378-
};
4379-
InnerObserver.prototype.onCompleted = function () {
4380-
if(!this.isStopped) {
4381-
this.isStopped = true;
4382-
this.o.onCompleted();
4383-
}
4384-
};
4385-
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
4386-
InnerObserver.prototype.fail = function (e) {
4387-
if (!this.isStopped) {
4388-
this.isStopped = true;
4389-
this.observer.onError(e);
4390-
return true;
4391-
}
4392-
4393-
return false;
4394-
};
4395-
4396-
return IgnoreElementsObservable;
4397-
}(ObservableBase));
4398-
4399-
/**
4357+
var IgnoreElementsObservable = (function(__super__) {
4358+
inherits(IgnoreElementsObservable, __super__);
4359+
4360+
function IgnoreElementsObservable(source) {
4361+
this.source = source;
4362+
__super__.call(this);
4363+
}
4364+
4365+
IgnoreElementsObservable.prototype.subscribeCore = function (o) {
4366+
return this.source.subscribe(new InnerObserver(o));
4367+
};
4368+
4369+
function InnerObserver(o) {
4370+
this.o = o;
4371+
this.isStopped = false;
4372+
}
4373+
InnerObserver.prototype.onNext = noop;
4374+
InnerObserver.prototype.onError = function (err) {
4375+
if(!this.isStopped) {
4376+
this.isStopped = true;
4377+
this.o.onError(err);
4378+
}
4379+
};
4380+
InnerObserver.prototype.onCompleted = function () {
4381+
if(!this.isStopped) {
4382+
this.isStopped = true;
4383+
this.o.onCompleted();
4384+
}
4385+
};
4386+
InnerObserver.prototype.dispose = function() { this.isStopped = true; };
4387+
InnerObserver.prototype.fail = function (e) {
4388+
if (!this.isStopped) {
4389+
this.isStopped = true;
4390+
this.observer.onError(e);
4391+
return true;
4392+
}
4393+
4394+
return false;
4395+
};
4396+
4397+
return IgnoreElementsObservable;
4398+
}(ObservableBase));
4399+
4400+
/**
44004401
* Ignores all elements in an observable sequence leaving only the termination messages.
44014402
* @returns {Observable} An empty observable sequence that signals termination, successful or exceptional, of the source sequence.
44024403
*/
@@ -5225,6 +5226,57 @@
52255226
}, source);
52265227
};
52275228

5229+
var TakeObservable = (function(__super__) {
5230+
inherits(TakeObservable, __super__);
5231+
5232+
function TakeObservable(source, count) {
5233+
this.source = source;
5234+
this.count = count;
5235+
__super__.call(this);
5236+
}
5237+
5238+
TakeObservable.prototype.subscribeCore = function (o) {
5239+
return this.source.subscribe(new InnerObserver(o, this.count));
5240+
};
5241+
5242+
function InnerObserver(o, c) {
5243+
this.o = o;
5244+
this.c = c;
5245+
this.r = c;
5246+
this.isStopped = false;
5247+
}
5248+
InnerObserver.prototype.onNext = function (x) {
5249+
if (this.isStopped) { return; }
5250+
if (this.r-- > 0) {
5251+
this.o.onNext(x);
5252+
this.r === 0 && this.o.onCompleted();
5253+
}
5254+
};
5255+
InnerObserver.prototype.onError = function (err) {
5256+
if (!this.isStopped) {
5257+
this.isStopped = true;
5258+
this.o.onError(err);
5259+
}
5260+
};
5261+
InnerObserver.prototype.onCompleted = function () {
5262+
if (!this.isStopped) {
5263+
this.isStopped = true;
5264+
this.o.onCompleted();
5265+
}
5266+
};
5267+
InnerObserver.prototype.dispose = function () { this.isStopped = true; };
5268+
InnerObserver.prototype.fail = function (e) {
5269+
if (!this.isStopped) {
5270+
this.isStopped = true;
5271+
this.o.onError(e);
5272+
return true;
5273+
}
5274+
return false;
5275+
}
5276+
5277+
return TakeObservable;
5278+
}(ObservableBase));
5279+
52285280
/**
52295281
* Returns a specified number of contiguous elements from the start of an observable sequence, using the specified scheduler for the edge case of take(0).
52305282
*
@@ -5237,16 +5289,7 @@
52375289
observableProto.take = function (count, scheduler) {
52385290
if (count < 0) { throw new ArgumentOutOfRangeError(); }
52395291
if (count === 0) { return observableEmpty(scheduler); }
5240-
var source = this;
5241-
return new AnonymousObservable(function (o) {
5242-
var remaining = count;
5243-
return source.subscribe(function (x) {
5244-
if (remaining-- > 0) {
5245-
o.onNext(x);
5246-
remaining === 0 && o.onCompleted();
5247-
}
5248-
}, function (e) { o.onError(e); }, function () { o.onCompleted(); });
5249-
}, source);
5292+
return new TakeObservable(this, count);
52505293
};
52515294

52525295
/**

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: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)