JVM, JS: Use faster checks in IdePlatformKind.supportsTargetPlatform()
This commit is contained in:
@@ -61,14 +61,16 @@ class JdkPlatform(val targetVersion: JvmTarget) : JvmPlatform() {
|
|||||||
get() = targetVersion
|
get() = targetVersion
|
||||||
|
|
||||||
// TODO(dsavvinov): temporarily conservative measure; make JdkPlatform data class later
|
// TODO(dsavvinov): temporarily conservative measure; make JdkPlatform data class later
|
||||||
// Explanation: previously we had only one JvmPlatform, and all 'TargetPlatform's had an
|
// Explanation: previously we had only one JvmPlatform, and all 'TargetPlatform's had an
|
||||||
// equality (actually, identity, because each platform had only one instance). This lead
|
// equality (actually, identity, because each platform had only one instance). This lead
|
||||||
// to common pattern of putting them in map (e.g., see KotlinCacheServiceImpl.globalFacadesPerPlatformAndSdk).
|
// to common pattern of putting them in map (e.g., see KotlinCacheServiceImpl.globalFacadesPerPlatformAndSdk).
|
||||||
//
|
// .
|
||||||
// If we start distinguishing JvmPlatforms with different JvmTarget right now, it may accidentally
|
// If we start distinguishing JvmPlatforms with different JvmTarget right now, it may accidentally
|
||||||
// break some clients (in particular, we'll create global facade for *each* JvmTarget, which is a bad idea)
|
// break some clients (in particular, we'll create global facade for *each* JvmTarget, which is a bad idea)
|
||||||
override fun equals(other: Any?): Boolean = other is JdkPlatform
|
override fun equals(other: Any?): Boolean = other is JdkPlatform
|
||||||
override fun hashCode(): Int = JdkPlatform::class.hashCode()
|
override fun hashCode(): Int = JdkPlatform::class.hashCode()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: temporarily conservative implementation; use the same approach as for TargetPlatform?.isNative()
|
||||||
|
// when JdkPlatform becomes a data class
|
||||||
fun TargetPlatform?.isJvm(): Boolean = this?.singleOrNull() is JvmPlatform
|
fun TargetPlatform?.isJvm(): Boolean = this?.singleOrNull() is JvmPlatform
|
||||||
@@ -15,9 +15,10 @@ import org.jetbrains.kotlin.platform.IdePlatformKind
|
|||||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
import org.jetbrains.kotlin.platform.TargetPlatformVersion
|
import org.jetbrains.kotlin.platform.TargetPlatformVersion
|
||||||
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
import org.jetbrains.kotlin.platform.js.JsPlatforms
|
||||||
|
import org.jetbrains.kotlin.platform.js.isJs
|
||||||
|
|
||||||
object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
|
object JsIdePlatformKind : IdePlatformKind<JsIdePlatformKind>() {
|
||||||
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platforms.contains(platform)
|
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isJs()
|
||||||
|
|
||||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||||
return if (arguments is K2JSCompilerArguments)
|
return if (arguments is K2JSCompilerArguments)
|
||||||
|
|||||||
@@ -16,9 +16,10 @@ import org.jetbrains.kotlin.platform.IdePlatform
|
|||||||
import org.jetbrains.kotlin.platform.IdePlatformKind
|
import org.jetbrains.kotlin.platform.IdePlatformKind
|
||||||
import org.jetbrains.kotlin.platform.TargetPlatform
|
import org.jetbrains.kotlin.platform.TargetPlatform
|
||||||
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
import org.jetbrains.kotlin.platform.jvm.JvmPlatforms
|
||||||
|
import org.jetbrains.kotlin.platform.jvm.isJvm
|
||||||
|
|
||||||
object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
|
object JvmIdePlatformKind : IdePlatformKind<JvmIdePlatformKind>() {
|
||||||
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platforms.contains(platform)
|
override fun supportsTargetPlatform(platform: TargetPlatform): Boolean = platform.isJvm()
|
||||||
|
|
||||||
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
override fun platformByCompilerArguments(arguments: CommonCompilerArguments): TargetPlatform? {
|
||||||
if (arguments !is K2JVMCompilerArguments) return null
|
if (arguments !is K2JVMCompilerArguments) return null
|
||||||
|
|||||||
@@ -34,4 +34,6 @@ object JsPlatforms {
|
|||||||
val allJsPlatforms: List<TargetPlatform> = listOf(defaultJsPlatform)
|
val allJsPlatforms: List<TargetPlatform> = listOf(defaultJsPlatform)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: temporarily conservative implementation; use the same approach as for TargetPlatform?.isNative()
|
||||||
|
// when JsPlatform will become parameterized with "JS target"
|
||||||
fun TargetPlatform?.isJs(): Boolean = this?.singleOrNull() is JsPlatform
|
fun TargetPlatform?.isJs(): Boolean = this?.singleOrNull() is JsPlatform
|
||||||
|
|||||||
Reference in New Issue
Block a user