From 88c8f2488735427ebb5170dda6268effaf351d10 Mon Sep 17 00:00:00 2001 From: Zalim Bashorov Date: Wed, 21 Oct 2015 23:14:16 +0300 Subject: [PATCH] Caching results of JpsUtils#isJsKotlinModule #KT-9636 Fixed --- .../jetbrains/kotlin/jps/build/JpsUtils.java | 53 +++++++++++++++++-- 1 file changed, 50 insertions(+), 3 deletions(-) diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java b/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java index 86562fc6785..4ab593ed174 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/JpsUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,11 +27,18 @@ import org.jetbrains.jps.model.library.JpsOrderRootType; import org.jetbrains.jps.util.JpsPathUtil; import org.jetbrains.kotlin.utils.LibraryUtils; +import java.util.AbstractMap; +import java.util.Collections; +import java.util.Map; import java.util.Set; +import java.util.concurrent.ConcurrentHashMap; class JpsUtils { private JpsUtils() {} + private static final Map IS_KOTLIN_JS_MODULE_CACHE = createMapForCaching(); + private static final Map IS_KOTLIN_JS_STDLIB_JAR_CACHE = createMapForCaching(); + @NotNull static JpsJavaDependenciesEnumerator getAllDependencies(@NotNull ModuleBuildTarget target) { return JpsJavaExtensionService.dependencies(target.getModule()).recursively().exportedOnly() @@ -39,13 +46,53 @@ class JpsUtils { } static boolean isJsKotlinModule(@NotNull ModuleBuildTarget target) { + Boolean cachedValue = IS_KOTLIN_JS_MODULE_CACHE.get(target); + if (cachedValue != null) return cachedValue; + + boolean isKotlinJsModule = isJsKotlinModuleImpl(target); + IS_KOTLIN_JS_MODULE_CACHE.put(target, isKotlinJsModule); + + return isKotlinJsModule; + } + + private static boolean isJsKotlinModuleImpl(@NotNull ModuleBuildTarget target) { Set libraries = getAllDependencies(target).getLibraries(); for (JpsLibrary library : libraries) { for (JpsLibraryRoot root : library.getRoots(JpsOrderRootType.COMPILED)) { - if (LibraryUtils.isKotlinJavascriptStdLibrary(JpsPathUtil.urlToFile(root.getUrl()))) - return true; + String url = root.getUrl(); + + Boolean cachedValue = IS_KOTLIN_JS_STDLIB_JAR_CACHE.get(url); + if (cachedValue != null) return cachedValue; + + boolean isKotlinJavascriptStdLibrary = LibraryUtils.isKotlinJavascriptStdLibrary(JpsPathUtil.urlToFile(url)); + IS_KOTLIN_JS_STDLIB_JAR_CACHE.put(url, isKotlinJavascriptStdLibrary); + if (isKotlinJavascriptStdLibrary) return true; } } return false; } + + private static Map createMapForCaching() { + if ("true".equalsIgnoreCase(System.getProperty("kotlin.jps.tests"))) { + return new AbstractMap() { + @Override + public V put(K key, V value) { + return null; + } + + @Override + public V get(Object key) { + return null; + } + + @NotNull + @Override + public Set> entrySet() { + return Collections.emptySet(); + } + }; + } + + return new ConcurrentHashMap(); + } }