Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: tango/core/Array.d
- ===================================================================
- --- tango/core/Array.d (revision 5688)
- +++ tango/core/Array.d (working copy)
- @@ -3625,18 +3625,19 @@
- ParameterTupleOf!(Pred)[0][] filter(Array array, Pred pred, ParameterTupleOf!(Pred)[0][] buf = null)
- {
- - // Unfortunately, we don't know our output size -- it could be empty or
- - // the length of the input array. So we won't try to do anything fancy
- - // with preallocation.
- - buf.length = 0;
- - foreach (i, e; array)
- + size_t idx = 0;
- + foreach (e; array)
- {
- if (pred(e))
- {
- - buf ~= e;
- + if (idx < buf.length)
- + buf[idx] = e;
- + else
- + buf ~= e;
- + idx++;
- }
- }
- - return buf;
- + return buf[0..idx];
- }
- }
Add Comment
Please, Sign In to add comment