Commit 19c6b200 authored by Hendrik von Prince's avatar Hendrik von Prince

improving the performance of "take": it won't any longer iterate through the…

improving the performance of "take": it won't any longer iterate through the whole sequence, only the items it needs to
parent 237edd05
...@@ -171,7 +171,11 @@ namespace boolinq ...@@ -171,7 +171,11 @@ namespace boolinq
LinqObj<Enumerator<T,std::pair<TE,int> > > take(int count) const LinqObj<Enumerator<T,std::pair<TE,int> > > take(int count) const
{ {
return where_i([=](T, int i){return i < count;}); return where_i([=](T, int i){
if(i == count)
throw EnumeratorEndException();
return true;
});
} }
LinqObj<Enumerator<T,std::pair<TE,int> > > takeWhile_i(std::function<bool(T,int)> predicate) const LinqObj<Enumerator<T,std::pair<TE,int> > > takeWhile_i(std::function<bool(T,int)> predicate) const
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment