From 29c6445084527762368e12bcf20869aef76d00ef Mon Sep 17 00:00:00 2001 From: Azalea Date: Tue, 19 Mar 2024 21:21:04 -0700 Subject: [PATCH] [O] Optimize lines() --- libraries/stdlib/src/kotlin/text/Strings.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/stdlib/src/kotlin/text/Strings.kt b/libraries/stdlib/src/kotlin/text/Strings.kt index 87cc1bf3188..079087b4e22 100644 --- a/libraries/stdlib/src/kotlin/text/Strings.kt +++ b/libraries/stdlib/src/kotlin/text/Strings.kt @@ -1403,14 +1403,14 @@ public inline fun CharSequence.splitToSequence(regex: Regex, limit: Int = 0): Se * * The lines returned do not include terminating line separators. */ -public fun CharSequence.lineSequence(): Sequence = splitToSequence("\r\n", "\n", "\r") +public fun CharSequence.lineSequence(): Sequence = toString().replace("\r\n", "\n").splitToSequence('\r', '\n') /** * Splits this char sequence to a list of lines delimited by any of the following character sequences: CRLF, LF or CR. * * The lines returned do not include terminating line separators. */ -public fun CharSequence.lines(): List = lineSequence().toList() +public fun CharSequence.lines(): List = toString().replace("\r\n", "\n").split('\r', '\n') /** * Returns `true` if the contents of this char sequence are equal to the contents of the specified [other],