Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize fs2.text.{char2string,string2char} #3278

Merged
merged 1 commit into from
Aug 28, 2023

Conversation

armanbilge
Copy link
Member

No description provided.

@armanbilge armanbilge changed the title Optimize fs2.text.{chars2string,string2char} Optimize fs2.text.{char2string,string2char} Aug 15, 2023
Copy link
Contributor

@ybasket ybasket left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

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)
Copy link

@filipwiech filipwiech Aug 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be a good idea to use the UTF-8 charset instead of relying on the default one, like we do in a few other places where we create a new String (private val utf8Charset = Charset.forName("UTF-8"))? 🙂

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, not sure. Perhaps you are mixing up the ctor that takes an Array[Byte] with the one we are using here, which takes an Array[Char]?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, that's it, you're right, sorry for the confusion. 😅

@mpilquist mpilquist merged commit 213d5d1 into typelevel:main Aug 28, 2023
14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants