From 9d753f24b76d33a9e01f878ecf3ef06265a349d3 Mon Sep 17 00:00:00 2001 From: Ilya Gorbunov Date: Mon, 14 Dec 2015 06:04:08 +0300 Subject: [PATCH] Do not create regex to split path by directory separator char. --- libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt b/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt index 1c0ba388f52..82701ce7309 100644 --- a/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt +++ b/libraries/stdlib/src/kotlin/io/files/FilePathComponents.kt @@ -138,11 +138,7 @@ internal fun File.toComponents(): FilePathComponents { val rootLength = path.getRootLength() val rootName = path.substring(0, rootLength) val subPath = path.substring(rootLength) - // if: a special case when we have only root component - // Split not only by / or \, but also by //, ///, \\, \\\, etc. - val list = if (subPath.isEmpty()) listOf() else - // Looks awful but we split just by /+ or \+ depending on OS - subPath.split(Regex.fromLiteral(File.separatorChar.toString())).map { it -> File(it) } + val list = if (subPath.isEmpty()) listOf() else subPath.split(File.separatorChar).map { File(it) } return FilePathComponents(File(rootName), list) }