Skip to content

Commit

Permalink
Merge pull request #3278 from armanbilge/topic/optimize-char2string
Browse files Browse the repository at this point in the history
Optimize `fs2.text.{char2string,string2char}`
  • Loading branch information
mpilquist authored Aug 28, 2023
2 parents 1c4939f + 1313576 commit 213d5d1
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 213d5d1

Please sign in to comment.