- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Why override foreach on VectorViewTemplate.Transformed subclasses?
Mon, 2009-06-29, 22:57
Hi,
after checking the resulting byte code for VectorViewTemplate$$anon$9
and comparing with my VectorViewTemplate$$anon$10 after applying my
patch contained in https://lampsvn.epfl.ch/trac/scala/ticket/2074, I
see that leaving out the override for foreach makes the call just one
bit more direct as it is not dispatched via VectorViewTemplate$Zipped.
What was the rationale? The comment at the top mentions execution
speed, but that seems to be non-tested.
Also, if I'm zipping an Array with a List, then "foreach" on the
result uses apply() on the List, which is inefficient. In that case,
it would be preferable to use Iterable.foreach. Could this be done
using implicits? It would be nice to build one kind of Zipped for
Vectors and another for the rest...
Ciao,
Roland
Sat, 2009-07-04, 01:47
#2
Re: Why override foreach on VectorViewTemplate.Transformed sub
It would be nice to keep the while loop from VectorTemplate in case of
Vectors and fall back to iterators otherwise. There was a discussion
about conditional definitions based on type comparisons the other day,
in which implicits were mentioned as a possible solution, but I have
yet to understand how that was meant to play out. And then I'll have
to benchmark the difference and check whether I'm fooling myself on
this one.
Ciao,
Roland
On 2 Jul 2009, at 07:01, Jorge Ortiz wrote:
> I haven't looked at your code (I'm on my phone) but if you implement
> Zipped's foreach with iterators of both of the underlying collections,
> you should get efficient access for both Lists and Vectors.
>
> --j
>
> On Monday, June 29, 2009, Roland Kuhn wrote:
>> Hi,
>>
>> after checking the resulting byte code for VectorViewTemplate$$anon
>> $9 and comparing with my VectorViewTemplate$$anon$10 after applying
>> my patch contained in https://lampsvn.epfl.ch/trac/scala/ticket/
>> 2074, I see that leaving out the override for foreach makes the
>> call just one bit more direct as it is not dispatched via
>> VectorViewTemplate$Zipped. What was the rationale? The comment at
>> the top mentions execution speed, but that seems to be non-tested.
>>
>> Also, if I'm zipping an Array with a List, then "foreach" on the
>> result uses apply() on the List, which is inefficient. In that
>> case, it would be preferable to use Iterable.foreach. Could this be
>> done using implicits? It would be nice to build one kind of Zipped
>> for Vectors and another for the rest...
>>
>> Ciao,
>>
>> Roland
>>
I haven't looked at your code (I'm on my phone) but if you implement
Zipped's foreach with iterators of both of the underlying collections,
you should get efficient access for both Lists and Vectors.
--j
On Monday, June 29, 2009, Roland Kuhn wrote:
> Hi,
>
> after checking the resulting byte code for VectorViewTemplate$$anon$9 and comparing with my VectorViewTemplate$$anon$10 after applying my patch contained in https://lampsvn.epfl.ch/trac/scala/ticket/2074, I see that leaving out the override for foreach makes the call just one bit more direct as it is not dispatched via VectorViewTemplate$Zipped. What was the rationale? The comment at the top mentions execution speed, but that seems to be non-tested.
>
> Also, if I'm zipping an Array with a List, then "foreach" on the result uses apply() on the List, which is inefficient. In that case, it would be preferable to use Iterable.foreach. Could this be done using implicits? It would be nice to build one kind of Zipped for Vectors and another for the rest...
>
> Ciao,
>
> Roland
>