Skip to content

PagedSeq is not lazy enough #6519

@scabug

Description

@scabug

The following code results in evaluation of the whole file:

scala> import collection.immutable.PagedSeq
scala> val in = new java.io.StringReader("t"*10000){override def read(c:Array[Char],o:Int,l:Int)={println("Read: "+l);super.read(c,o,l)}}
scala> PagedSeq.fromReader(in).slice(0,2).mkString
Read: 4096
Read: 4096
Read: 4096
Read: 2288

I think this shouldn't be happening, since I am actually requesting only 2 characters from the input, not the whole file. Same thing happens if I call .toList on that slice.

Also what troubles me is that total of 14576 characters is read (4096*3+2288), while it should be exactly 10000 (length of the string).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions