[phobos] phobos commit, revision 1566
Andrei Alexandrescu
andrei at erdani.com
Sat May 29 06:58:06 PDT 2010
Actually I was looking in the wrong place. The problem is this constructor:
1214 this(R input, size_t maxAvailable)
1215 {
1216 static if (backByBack)
1217 {
1218 while (input.length > maxAvailable)
1219 input.popBack;
1220 }
1221 _input = input;
1222 _maxAvailable = maxAvailable;
1223 }
This constructor is O(n), which is unacceptable. The whole backByBack
logic must be erased.
Andrei
On 05/29/2010 08:44 AM, dsource.org wrote:
> phobos commit, revision 1566
>
>
> user: rsinfu
>
> msg:
> Fixed bugzilla 3876: std.range.Take back/popBack methods don't work correctly.
> Thanks to Philippe Sigaud for the proposed solution. It was helpful.
>
> The former implementation simply used input.back for Take.back. It didn't work if input.length was larger than maxAvailable. For example:
> input = [ 1, 2, 3, 4, 5 ]
> s = take(input, 3) // [ 1, 2, 3 ]
> s.back == input.back == 5 // wrong!
>
> Take must pop all the excess elements from the input ([4,5] in the above example) to provide correct back element. This change makes it to do so if input is purely bidirectional. (random access is used instead if possible.)
>
> - Added Take.opSlice
> - Added some enforcement error messages
>
> http://www.dsource.org/projects/phobos/changeset/1566
>
> _______________________________________________
> phobos mailing list
> phobos at puremagic.com
> http://lists.puremagic.com/mailman/listinfo/phobos
More information about the phobos
mailing list