You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The concrete problem is that CharArrayReader's constructor implicitly uses Predef.arrayToCharSequence which implements CharSequence.subSequence by calling Array.slice on the underlying array which creates a new copy of the array containing the subsequence. Contrast this with String.subSequence which creates a shallow copy with only updated indices.
Using a CharArrayReader in parser combinators can therefore lead to really bad performance issues which can't be figured out easily.
The next question is if Predef.arrayToCharSequence really should implement subsequence by making a copy. The problem is that java.lang.CharSequence isn't explicit in what to expect from subSequence if the underlying data structure is mutable.
The text was updated successfully, but these errors were encountered:
OnTue, Apr3, 2012 at 2:25AM, martin odersky <martin.odersky@epfl.ch> wrote:
>OnMon, Apr2, 2012 at 3:51AM, JohannesRudolph>>1.) Create a shallow copy without copying in `subSequence`. This may
>> break code which relies on the `CharSequence` returned from
>> `subSequence` to be unchanged if the underlying array is mutated.
>>I would vote for1). Since the arrayToCharSequence does not copy the whole
> array when converting to a CharSequence, any arguments based on mutability
> are moot. SoI would classify this as a (performance) bug, which needs to be
> fixed.
The concrete problem is that
CharArrayReader
's constructor implicitly usesPredef.arrayToCharSequence
which implementsCharSequence.subSequence
by callingArray.slice
on the underlying array which creates a new copy of the array containing the subsequence. Contrast this withString.subSequence
which creates a shallow copy with only updated indices.Using a
CharArrayReader
in parser combinators can therefore lead to really bad performance issues which can't be figured out easily.The next question is if
Predef.arrayToCharSequence
really should implementsubsequence
by making a copy. The problem is thatjava.lang.CharSequence
isn't explicit in what to expect fromsubSequence
if the underlying data structure is mutable.The text was updated successfully, but these errors were encountered: