Skip to content

Commit

Permalink
Optimize fs2.text.{chars2string,string2char}
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Aug 15, 2023
1 parent 5dbe235 commit 1313576
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions core/shared/src/main/scala/fs2/text.scala
Original file line number Diff line number Diff line change
Expand Up @@ -563,10 +563,13 @@ object text {

/** Transforms a stream of `String` to a stream of `Char`. */
def string2char[F[_]]: Pipe[F, String, Char] =
_.map(s => Chunk.charBuffer(CharBuffer.wrap(s))).flatMap(Stream.chunk)
_.flatMap(s => Stream.chunk(Chunk.charBuffer(CharBuffer.wrap(s))))

/** Transforms a stream of `Char` to a stream of `String`. */
def char2string[F[_]]: Pipe[F, Char, String] = _.chunks.map(_.mkString_(""))
def char2string[F[_]]: Pipe[F, Char, String] = _.chunks.map { chunk =>
val Chunk.ArraySlice(chars, offset, length) = chunk.toArraySlice
new String(chars, offset, length)
}

class LineTooLongException(val length: Int, val max: Int)
extends RuntimeException(
Expand Down

0 comments on commit 1313576

Please sign in to comment.