On Tue, Jul 18, 2017 at 4:27 PM, Sven Van Caekenberghe <s...@stfx.eu> wrote:
>
> In general, the stream API is much, much too wide, IMHO. Not all streams 
> (hence the word stream) can see all their content all the time (think of 
> network or encrypted streams, most work with a sliding buffer, but in general 
> the idea of a stream is to *not* hold everything in memory at the same time). 
> If you look at it that way, many operations stop making sense. Positioning is 
> one of them. Even in Java not every stream is positionable, and even if they 
> are positionable, the positioning can fail because you go too far (back).
>
> In all parsing code that I write I try to only use 1 item look ahead (a 
> single item buffer), which means you can #peek 1 item, that's it.
>
> I know that we have parsing code that was written with other assumptions. 
> Such code is not stream based, IMHO.
>
> The solution (or rather workaround) is easy: read everything #upToEnd and 
> turn it into a good old ReadStream again. You will give the use infinite 
> positioning over all of the content, at the cost of more memory usage.


When I'll have time I'll check if we can avoid the use of #position:,
but in any case we cannot use #upToEnd because we need to stay
optimized.

At the begining we where doing that but it's too long for our algos.
Sometime we just want to read what it between the line 3, column 5 and
the line 6, column 9. If the file has thousands of line we lose to
much time to read everything.


-- 
Cyril Ferlicot
https://ferlicot.fr

http://www.synectique.eu
2 rue Jacques Prévert 01,
59650 Villeneuve d'ascq France

Reply via email to