From 18b42837f50dbd013cd196f1d1900f9ea459a91f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 15 Jun 2020 09:53:19 +0200 Subject: [PATCH] prefer jdk and fastutil collections GitOrigin-RevId: 91f15eef29d9ea8f6790ee4442d2c9bdb7bff9a9 --- .../daemon/DaemonAnalyzerTestCase.java | 6 +- .../daemon/LightDaemonAnalyzerTestCase.java | 8 +- .../jps/incremental/java/JavaBuilder.java | 6 +- .../fileTypes/impl/FileTypeAssocTable.java | 20 ++-- .../jps/model/ex/JpsElementContainerImpl.java | 22 +---- .../jps/model/java/impl/JavaSdkUtil.java | 5 +- .../compiler/ProcessorConfigProfileImpl.java | 23 +---- .../model/library/impl/JpsLibraryImpl.java | 8 +- .../impl/JpsDependenciesEnumeratorBase.java | 24 +---- .../builtInWebServer/StaticFileHandler.kt | 4 +- .../ssi/SsiExternalResolver.kt | 23 +---- .../builtInWebServer/ssi/SsiProcessor.kt | 27 +++--- .../builtInWebServer/ssi/Strftime.java | 19 ++-- .../jetbrains/io/fastCgi/FastCgiDecoder.kt | 11 +-- .../org/jetbrains/io/jsonRpc/ClientManager.kt | 37 +++++--- .../org/jetbrains/io/jsonRpc/JsonRpcServer.kt | 95 ++++++++++--------- .../intellij/core/CoreFileTypeRegistry.java | 26 +---- .../dupLocator/index/TracingData.java | 34 ++++--- .../treeHash/DuplocatorHashCallback.java | 46 ++++----- .../colors/impl/FontPreferencesImpl.java | 14 +-- .../psi/impl/search/IndexPatternSearcher.java | 19 ++-- .../execution/impl/RunDashboardTypesPanel.kt | 9 +- .../execution/ui/RunContentManagerImpl.kt | 3 +- .../ExternalSystemTaskExecutionSettings.java | 6 +- .../AbstractExternalSystemLocalSettings.java | 12 +-- .../autoimport/ProjectNotificationAware.kt | 12 +-- .../ExternalSystemStreamProviderFactory.kt | 5 +- .../manage/ContentRootDataService.java | 18 ++-- .../project/manage/SourceFolderManagerImpl.kt | 13 ++- .../ui/ConfigureTasksActivationDialog.java | 8 +- .../test/ExternalSystemTestCase.java | 8 +- .../intellij/psi/search/FilenameIndex.java | 11 +-- .../searches/DefinitionsScopedSearch.java | 4 +- .../intellij/codeInsight/hints/HintsBuffer.kt | 52 +++++----- .../codeInsight/hints/InlayHintsPass.kt | 40 ++++---- .../codeInsight/hints/InlayHintsSinkImpl.kt | 23 ++--- .../impl/config/IntentionManagerSettings.java | 4 +- .../ui/ProblemDescriptionNode.java | 6 +- .../execution/console/PrefixHistoryModel.kt | 17 ++-- .../impl/ProjectRootManagerComponent.java | 15 +-- .../execution/process/OSProcessHandler.java | 4 +- .../process/impl/ProcessListUtil.java | 6 +- .../src/com/intellij/util/Urls.kt | 14 +-- .../src/org/jetbrains/io/FileResponses.kt | 6 +- .../smartTree/CachingChildrenTreeNode.java | 13 +-- .../intellij/util/io/PersistentHashMap.java | 4 +- 46 files changed, 347 insertions(+), 443 deletions(-) diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java index 229c07603449..36b488e0722b 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/DaemonAnalyzerTestCase.java @@ -47,7 +47,7 @@ import com.intellij.testFramework.InspectionsKt; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; import com.intellij.util.containers.ContainerUtil; import com.intellij.xml.XmlSchemaProvider; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -278,7 +278,7 @@ public abstract class DaemonAnalyzerTestCase extends JavaCodeInsightTestCase { protected List doHighlighting() { PsiDocumentManager.getInstance(myProject).commitAllDocuments(); - TIntArrayList toIgnore = new TIntArrayList(); + IntArrayList toIgnore = new IntArrayList(); if (!doTestLineMarkers()) { toIgnore.add(Pass.LINE_MARKERS); } @@ -295,7 +295,7 @@ public abstract class DaemonAnalyzerTestCase extends JavaCodeInsightTestCase { } boolean canChange = canChangeDocumentDuringHighlighting(); - List infos = CodeInsightTestFixtureImpl.instantiateAndRun(getFile(), getEditor(), toIgnore.toNativeArray(), canChange); + List infos = CodeInsightTestFixtureImpl.instantiateAndRun(getFile(), getEditor(), toIgnore.toIntArray(), canChange); if (!canChange) { Document document = getDocument(getFile()); diff --git a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java index 69473756afed..36e3325e1514 100644 --- a/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java +++ b/java/testFramework/src/com/intellij/codeInsight/daemon/LightDaemonAnalyzerTestCase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.daemon; import com.intellij.codeHighlighting.Pass; @@ -19,7 +19,7 @@ import com.intellij.testFramework.HighlightTestInfo; import com.intellij.testFramework.LightJavaCodeInsightTestCase; import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; import com.intellij.util.ArrayUtilRt; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -144,7 +144,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightJavaCodeInsightTe protected List doHighlighting() { PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); - TIntArrayList toIgnoreList = new TIntArrayList(); + IntArrayList toIgnoreList = new IntArrayList(); if (!doFolding()) { toIgnoreList.add(Pass.UPDATE_FOLDING); } @@ -152,7 +152,7 @@ public abstract class LightDaemonAnalyzerTestCase extends LightJavaCodeInsightTe toIgnoreList.add(Pass.LOCAL_INSPECTIONS); toIgnoreList.add(Pass.WHOLE_FILE_LOCAL_INSPECTIONS); } - int[] toIgnore = toIgnoreList.isEmpty() ? ArrayUtilRt.EMPTY_INT_ARRAY : toIgnoreList.toNativeArray(); + int[] toIgnore = toIgnoreList.isEmpty() ? ArrayUtilRt.EMPTY_INT_ARRAY : toIgnoreList.toIntArray(); Editor editor = getEditor(); PsiFile file = getFile(); if (editor instanceof EditorWindow) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index d1c8a01e74fe..72b5f98a9731 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -74,7 +74,7 @@ import static com.intellij.openapi.util.Pair.pair; /** * @author Eugene Zhuravlev */ -public class JavaBuilder extends ModuleLevelBuilder { +public final class JavaBuilder extends ModuleLevelBuilder { private static final Logger LOG = Logger.getInstance(JavaBuilder.class); private static final String JAVA_EXTENSION = "java"; @@ -1121,7 +1121,7 @@ public class JavaBuilder extends ModuleLevelBuilder { return map; } - private static class DiagnosticSink implements DiagnosticOutputConsumer { + private static final class DiagnosticSink implements DiagnosticOutputConsumer { private final CompileContext myContext; private final AtomicInteger myErrorCount = new AtomicInteger(0); private final AtomicInteger myWarningCount = new AtomicInteger(0); @@ -1281,7 +1281,7 @@ public class JavaBuilder extends ModuleLevelBuilder { } } - private class ClassProcessingConsumer implements OutputFileConsumer { + private final class ClassProcessingConsumer implements OutputFileConsumer { private final CompileContext myContext; private final OutputFileConsumer myDelegateOutputFileSink; diff --git a/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java b/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java index a4d8bbd41d27..64c2734d4679 100644 --- a/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java +++ b/jps/model-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeAssocTable.java @@ -8,8 +8,9 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.util.ArrayUtilRt; -import com.intellij.util.text.CharSequenceHashingStrategy; -import gnu.trove.THashMap; +import com.intellij.util.containers.CollectionFactory; +import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -17,7 +18,7 @@ import org.jetbrains.annotations.Nullable; import java.util.*; import java.util.stream.Collectors; -public class FileTypeAssocTable { +public final class FileTypeAssocTable { private final Map myExtensionMappings; private final Map myExactFileNameMappings; private final Map myExactFileNameAnyCaseMappings; @@ -29,13 +30,13 @@ public class FileTypeAssocTable { @NotNull Map exactFileNameAnyCaseMappings, @NotNull Map hashBangMap, @NotNull List> matchingMappings) { - myExtensionMappings = new THashMap<>(Math.max(10, extensionMappings.size()), 0.5f, CharSequenceHashingStrategy.CASE_INSENSITIVE); + myExtensionMappings = CollectionFactory.createCharSequenceMap(false, Math.max(10, extensionMappings.size()), 0.5f); myExtensionMappings.putAll(extensionMappings); - myExactFileNameMappings = new THashMap<>(Math.max(10, exactFileNameMappings.size()), 0.5f, CharSequenceHashingStrategy.CASE_SENSITIVE); + myExactFileNameMappings = CollectionFactory.createCharSequenceMap(true, Math.max(10, exactFileNameMappings.size()), 0.5f); myExactFileNameMappings.putAll(exactFileNameMappings); - myExactFileNameAnyCaseMappings = new THashMap<>(Math.max(10, exactFileNameAnyCaseMappings.size()), 0.5f, CharSequenceHashingStrategy.CASE_INSENSITIVE); + myExactFileNameAnyCaseMappings = CollectionFactory.createCharSequenceMap(false, Math.max(10, exactFileNameAnyCaseMappings.size()), 0.5f); myExactFileNameAnyCaseMappings.putAll(exactFileNameAnyCaseMappings); - myHashBangMap = new THashMap<>(Math.max(10, hashBangMap.size()), 0.5f); + myHashBangMap = new Object2ObjectOpenHashMap<>(Math.max(10, hashBangMap.size()), 0.5f); myHashBangMap.putAll(hashBangMap); myMatchingMappings = new ArrayList<>(matchingMappings); } @@ -275,8 +276,7 @@ public class FileTypeAssocTable { return result; } - @NotNull - Map getAllHashBangPatterns() { - return Collections.unmodifiableMap(new THashMap<>(myHashBangMap)); + @NotNull Map getAllHashBangPatterns() { + return Object2ObjectMaps.unmodifiable(new Object2ObjectOpenHashMap<>(myHashBangMap)); } } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java index 4a3081f677df..5370cc2648e3 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/ex/JpsElementContainerImpl.java @@ -1,21 +1,7 @@ -/* - * Copyright 2000-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.ex; -import gnu.trove.THashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.*; @@ -27,7 +13,7 @@ import java.util.function.Supplier; public class JpsElementContainerImpl extends JpsElementContainerEx implements JpsElementContainer { private final Object myDataLock = new Object(); - private final Map, JpsElement> myElements = new THashMap<>(1); + private final Map, JpsElement> myElements = new Object2ObjectOpenHashMap<>(1); private final @NotNull JpsCompositeElementBase myParent; public JpsElementContainerImpl(@NotNull JpsCompositeElementBase parent) { @@ -161,7 +147,7 @@ public class JpsElementContainerImpl extends JpsElementContainerEx implements Jp @Override public void applyChanges(@NotNull JpsElementContainerEx modified) { final Collection> roles = new ArrayList<>(); - + synchronized (myDataLock) { roles.addAll(myElements.keySet()); } diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaSdkUtil.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaSdkUtil.java index fb3deff30b2c..23d078838f0b 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaSdkUtil.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/JavaSdkUtil.java @@ -3,12 +3,11 @@ package org.jetbrains.jps.model.java.impl; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileFilters; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.util.registry.Registry; import com.intellij.util.ArrayUtilRt; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -53,7 +52,7 @@ public final class JavaSdkUtil { } FileFilter jarFileFilter = FileFilters.filesWithExtension("jar"); - Set pathFilter = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); + Set pathFilter = CollectionFactory.createFilePathSet(); List rootFiles = new ArrayList<>(); if (Registry.is("project.structure.add.tools.jar.to.new.jdk", false)) { File toolsJar = new File(home, "lib/tools.jar"); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/ProcessorConfigProfileImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/ProcessorConfigProfileImpl.java index 964f02f8ba5a..66eb8834d85f 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/ProcessorConfigProfileImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/java/impl/compiler/ProcessorConfigProfileImpl.java @@ -1,22 +1,6 @@ -/* - * Copyright 2000-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.java.impl.compiler; -import gnu.trove.THashMap; -import gnu.trove.THashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.java.compiler.ProcessorConfigProfile; @@ -27,19 +11,18 @@ import java.util.*; * @author Eugene Zhuravlev */ public final class ProcessorConfigProfileImpl implements ProcessorConfigProfile { - private String myName = ""; private boolean myEnabled = false; private boolean myObtainProcessorsFromClasspath = true; private String myProcessorPath = ""; private boolean myUseProcessorModulePath = false; private final Set myProcessors = new LinkedHashSet<>(1); // empty list means all discovered - private final Map myProcessorOptions = new THashMap<>(1); // key=value map of options + private final Map myProcessorOptions = new HashMap<>(1); // key=value map of options private String myGeneratedProductionDirectoryName = DEFAULT_PRODUCTION_DIR_NAME; private String myGeneratedTestsDirectoryName = DEFAULT_TESTS_DIR_NAME; private boolean myOutputRelativeToContentRoot = false; - private final Set myModuleNames = new THashSet<>(1); + private final Set myModuleNames = new HashSet<>(1); public ProcessorConfigProfileImpl(String name) { myName = name; diff --git a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java index e667ee3f0f1b..d515623dd348 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/library/impl/JpsLibraryImpl.java @@ -1,9 +1,8 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.library.impl; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; -import gnu.trove.THashSet; +import com.intellij.util.containers.CollectionFactory; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.*; @@ -18,7 +17,7 @@ import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; -public class JpsLibraryImpl

extends JpsNamedCompositeElementBase> implements JpsTypedLibrary

{ +public final class JpsLibraryImpl

extends JpsNamedCompositeElementBase> implements JpsTypedLibrary

{ private static final ConcurrentMap> ourRootRoles = new ConcurrentHashMap<>(); private final JpsLibraryType

myLibraryType; @@ -148,8 +147,7 @@ public class JpsLibraryImpl

extends JpsNamedCompositeEleme return urls; } - private static final Set AR_EXTENSIONS = - new THashSet<>(Arrays.asList("jar", "zip", "swc", "ane"), FileUtil.PATH_HASHING_STRATEGY); + private static final Set AR_EXTENSIONS = CollectionFactory.createFilePathSet(Arrays.asList("jar", "zip", "swc", "ane")); private static void collectArchives(File file, boolean recursively, List result) { final File[] children = file.listFiles(); diff --git a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesEnumeratorBase.java b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesEnumeratorBase.java index 26774399edf5..00615543705e 100644 --- a/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesEnumeratorBase.java +++ b/jps/model-impl/src/org/jetbrains/jps/model/module/impl/JpsDependenciesEnumeratorBase.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2012 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.jps.model.module.impl; import com.intellij.openapi.util.Condition; @@ -20,7 +6,7 @@ import com.intellij.util.CollectConsumer; import com.intellij.util.Consumer; import com.intellij.util.EmptyConsumer; import com.intellij.util.Processor; -import gnu.trove.THashSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.library.JpsLibrary; @@ -33,10 +19,10 @@ import java.util.Set; public abstract class JpsDependenciesEnumeratorBase implements JpsDependenciesEnumerator { private boolean myWithoutSdk; private boolean myWithoutLibraries; - protected boolean myWithoutDepModules; + private boolean myWithoutDepModules; private boolean myWithoutModuleSourceEntries; protected boolean myRecursively; - protected final Collection myRootModules; + private final Collection myRootModules; private Condition myCondition; protected JpsDependenciesEnumeratorBase(Collection rootModules) { @@ -105,7 +91,7 @@ public abstract class JpsDependenciesEnumeratorBase processor) { - THashSet processed = new THashSet<>(); + Set processed = new ObjectOpenHashSet<>(); for (JpsModule module : myRootModules) { if (!doProcessDependencies(module, processor, processed)) { return false; diff --git a/platform/built-in-server/src/org/jetbrains/builtInWebServer/StaticFileHandler.kt b/platform/built-in-server/src/org/jetbrains/builtInWebServer/StaticFileHandler.kt index 6ef0e0613968..780e88927fd8 100644 --- a/platform/built-in-server/src/org/jetbrains/builtInWebServer/StaticFileHandler.kt +++ b/platform/built-in-server/src/org/jetbrains/builtInWebServer/StaticFileHandler.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.builtInWebServer import com.intellij.openapi.project.Project @@ -58,7 +58,7 @@ private class StaticFileHandler : WebServerFileHandler() { private fun processSsi(file: Path, path: String, project: Project, request: FullHttpRequest, channel: Channel, extraHeaders: HttpHeaders) { if (ssiProcessor == null) { - ssiProcessor = SsiProcessor(false) + ssiProcessor = SsiProcessor() } val buffer = channel.alloc().ioBuffer() diff --git a/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiExternalResolver.kt b/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiExternalResolver.kt index 2cce2edcf430..09880474e13a 100644 --- a/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiExternalResolver.kt +++ b/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiExternalResolver.kt @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.builtInWebServer.ssi import com.intellij.openapi.project.Project @@ -20,7 +6,6 @@ import com.intellij.openapi.util.io.FileUtil import com.intellij.util.io.exists import com.intellij.util.io.lastModified import com.intellij.util.io.size -import gnu.trove.THashMap import io.netty.handler.codec.http.HttpRequest import org.jetbrains.builtInWebServer.WebServerPathToFileManager import java.nio.file.Path @@ -31,11 +16,11 @@ private val VARIABLE_NAMES = arrayOf("AUTH_TYPE", "CONTENT_LENGTH", "CONTENT_TYP "PATH_TRANSLATED", "QUERY_STRING", "QUERY_STRING_UNESCAPED", "REMOTE_ADDR", "REMOTE_HOST", "REMOTE_PORT", "REMOTE_USER", "REQUEST_METHOD", "REQUEST_URI", "SCRIPT_FILENAME", "SCRIPT_NAME", "SERVER_ADDR", "SERVER_NAME", "SERVER_PORT", "SERVER_PROTOCOL", "SERVER_SOFTWARE", "UNIQUE_ID") -class SsiExternalResolver(private val project: Project, +internal class SsiExternalResolver(private val project: Project, private val request: HttpRequest, private val parentPath: String, private val parentFile: Path) { - private val variables = THashMap() + private val variables = HashMap() fun addVariableNames(variableNames: MutableCollection) { for (variableName in VARIABLE_NAMES) { @@ -61,7 +46,7 @@ class SsiExternalResolver(private val project: Project, return parentFile.resolve(path) } - path = if (path[0] == '/') path else parentPath + '/' + path + path = if (path[0] == '/') path else "$parentPath/$path" val pathInfo = WebServerPathToFileManager.getInstance(project).getPathInfo(path, true) ?: return null if (pathInfo.ioFile == null) { return Paths.get(pathInfo.file!!.path) diff --git a/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiProcessor.kt b/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiProcessor.kt index f7504fc9f43d..5d460af2c39e 100644 --- a/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiProcessor.kt +++ b/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/SsiProcessor.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.builtInWebServer.ssi import com.intellij.openapi.diagnostic.Logger @@ -8,7 +8,6 @@ import com.intellij.util.io.lastModified import com.intellij.util.io.readChars import com.intellij.util.io.size import com.intellij.util.text.CharArrayUtil -import gnu.trove.THashMap import io.netty.buffer.ByteBufUtf8Writer import java.io.IOException import java.nio.file.Path @@ -19,10 +18,10 @@ internal val LOG = Logger.getInstance(SsiProcessor::class.java) internal const val COMMAND_START = "" -class SsiStopProcessingException : RuntimeException() +internal class SsiStopProcessingException : RuntimeException() -class SsiProcessor(allowExec: Boolean) { - private val commands: MutableMap = THashMap() +internal open class SsiProcessor { + private val commands: MutableMap = HashMap() init { commands.put("config", SsiCommand { state, _, paramNames, paramValues, writer -> @@ -71,11 +70,7 @@ class SsiProcessor(allowExec: Boolean) { writer.write(variableValue ?: "(none)") System.currentTimeMillis() }) - //noinspection StatementWithEmptyBody - if (allowExec) { - // commands.put("exec", new SsiExec()); - } - commands.put("include", SsiCommand { state, commandName, paramNames, paramValues, writer -> + commands.put("include", SsiCommand { state, _, paramNames, paramValues, writer -> var lastModified: Long = 0 val configErrorMessage = state.configErrorMessage for (i in paramNames.indices) { @@ -268,7 +263,7 @@ class SsiProcessor(allowExec: Boolean) { return lastModifiedDate } - protected fun parseParamNames(command: StringBuilder, start: Int): List { + private fun parseParamNames(command: StringBuilder, start: Int): List { var bIdx = start val values = SmartList() var inside = false @@ -314,7 +309,7 @@ class SsiProcessor(allowExec: Boolean) { } @SuppressWarnings("AssignmentToForLoopParameter") - protected fun parseParamValues(command: StringBuilder, start: Int, count: Int): Array? { + private fun parseParamValues(command: StringBuilder, start: Int, count: Int): Array? { var valueIndex = 0 var inside = false val values = arrayOfNulls(count) @@ -374,7 +369,7 @@ class SsiProcessor(allowExec: Boolean) { private fun parseCommand(instruction: StringBuilder): String { var firstLetter = -1 var lastLetter = -1 - for (i in 0..instruction.length - 1) { + for (i in instruction.indices) { val c = instruction[i] if (Character.isLetter(c)) { if (firstLetter == -1) { @@ -394,9 +389,9 @@ class SsiProcessor(allowExec: Boolean) { return if (firstLetter == -1) "" else instruction.substring(firstLetter, lastLetter + 1) } - protected fun charCmp(buf: CharSequence, index: Int, command: String): Boolean = CharArrayUtil.regionMatches(buf, index, index + command.length, command) + private fun charCmp(buf: CharSequence, index: Int, command: String): Boolean = CharArrayUtil.regionMatches(buf, index, index + command.length, command) - protected fun isSpace(c: Char): Boolean = c == ' ' || c == '\n' || c == '\t' || c == '\r' + private fun isSpace(c: Char): Boolean = c == ' ' || c == '\n' || c == '\t' || c == '\r' - protected fun isQuote(c: Char): Boolean = c == '\'' || c == '\"' || c == '`' + private fun isQuote(c: Char): Boolean = c == '\'' || c == '\"' || c == '`' } \ No newline at end of file diff --git a/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/Strftime.java b/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/Strftime.java index f5051ee455be..91f32766ea46 100644 --- a/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/Strftime.java +++ b/platform/built-in-server/src/org/jetbrains/builtInWebServer/ssi/Strftime.java @@ -16,13 +16,8 @@ */ package org.jetbrains.builtInWebServer.ssi; -import gnu.trove.THashMap; - import java.text.SimpleDateFormat; -import java.util.Date; -import java.util.Locale; -import java.util.Map; -import java.util.TimeZone; +import java.util.*; /** * Converts dates to strings using the same format specifiers as strftime @@ -43,9 +38,9 @@ import java.util.TimeZone; * @author Dan Sandberg */ @SuppressWarnings("SpellCheckingInspection") -public class Strftime { - protected static final Map translate = new THashMap<>(); - protected final SimpleDateFormat simpleDateFormat; +public final class Strftime { + private static final Map translate = new HashMap<>(); + private final SimpleDateFormat simpleDateFormat; static { translate.put("a", "EEE"); @@ -150,7 +145,7 @@ public class Strftime { * @param pattern The pattern to search * @return The modified pattern */ - protected String convertDateFormat(String pattern) { + private static String convertDateFormat(String pattern) { boolean inside = false; boolean mark = false; boolean modifiedCommand = false; @@ -203,7 +198,7 @@ public class Strftime { return buf.toString(); } - protected String quote(String str, boolean insideQuotes) { + private static String quote(String str, boolean insideQuotes) { String retVal = str; if (!insideQuotes) { retVal = '\'' + retVal + '\''; @@ -221,7 +216,7 @@ public class Strftime { * @param oldInside Flag value * @return True if new is inside buffer */ - protected boolean translateCommand(StringBuilder buf, String pattern, int index, boolean oldInside) { + private static boolean translateCommand(StringBuilder buf, String pattern, int index, boolean oldInside) { char firstChar = pattern.charAt(index); boolean newInside = oldInside; diff --git a/platform/built-in-server/src/org/jetbrains/io/fastCgi/FastCgiDecoder.kt b/platform/built-in-server/src/org/jetbrains/io/fastCgi/FastCgiDecoder.kt index f6bc3ec876ba..103bfed3f704 100644 --- a/platform/built-in-server/src/org/jetbrains/io/fastCgi/FastCgiDecoder.kt +++ b/platform/built-in-server/src/org/jetbrains/io/fastCgi/FastCgiDecoder.kt @@ -1,12 +1,12 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.io.fastCgi import com.intellij.util.Consumer -import gnu.trove.TIntObjectHashMap import io.netty.buffer.ByteBuf import io.netty.buffer.CompositeByteBuf import io.netty.channel.ChannelHandlerContext import io.netty.util.CharsetUtil +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap import org.jetbrains.io.Decoder internal const val HEADER_LENGTH = 8 @@ -37,7 +37,7 @@ internal class FastCgiDecoder(private val errorOutputConsumer: Consumer, private var contentLength: Int = 0 private var paddingLength: Int = 0 - private val dataBuffers = TIntObjectHashMap() + private val dataBuffers = Int2ObjectOpenHashMap() override fun messageReceived(context: ChannelHandlerContext, input: ByteBuf) { while (true) { @@ -79,15 +79,14 @@ internal class FastCgiDecoder(private val errorOutputConsumer: Consumer, override fun channelInactive(context: ChannelHandlerContext) { try { - if (!dataBuffers.isEmpty) { - dataBuffers.forEachEntry { _, buffer -> + if (!dataBuffers.isEmpty()) { + for (buffer in dataBuffers.values) { try { buffer.release() } catch (e: Throwable) { LOG.error(e) } - true } dataBuffers.clear() } diff --git a/platform/built-in-server/src/org/jetbrains/io/jsonRpc/ClientManager.kt b/platform/built-in-server/src/org/jetbrains/io/jsonRpc/ClientManager.kt index 55cc89e3ae0d..959028a7c5c1 100644 --- a/platform/built-in-server/src/org/jetbrains/io/jsonRpc/ClientManager.kt +++ b/platform/built-in-server/src/org/jetbrains/io/jsonRpc/ClientManager.kt @@ -1,29 +1,29 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.io.jsonRpc import com.intellij.openapi.Disposable import com.intellij.openapi.util.SimpleTimer -import gnu.trove.THashSet -import gnu.trove.TObjectProcedure import io.netty.buffer.ByteBuf import io.netty.channel.Channel import io.netty.util.AttributeKey +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet import org.jetbrains.concurrency.Promise import org.jetbrains.io.webSocket.WebSocketServerOptions +import java.util.function.Consumer +import java.util.function.Predicate internal val CLIENT = AttributeKey.valueOf("SocketHandler.client") class ClientManager(private val listener: ClientListener?, val exceptionHandler: ExceptionHandler, options: WebSocketServerOptions? = null) : Disposable { private val heartbeatTimer = SimpleTimer.getInstance().setUp({ - forEachClient(TObjectProcedure { - if (it.channel.isActive) { - it.sendHeartbeat() - } - true - }) + forEachClient(Consumer { + if (it.channel.isActive) { + it.sendHeartbeat() + } + }) }, (options ?: WebSocketServerOptions()).heartbeatDelay.toLong()) - private val clients = THashSet() + private val clients = ObjectOpenHashSet() fun addClient(client: Client) { synchronized (clients) { @@ -48,10 +48,10 @@ class ClientManager(private val listener: ClientListener?, val exceptionHandler: } fun send(messageId: Int, message: ByteBuf, results: MutableList>>? = null) { - forEachClient(object : TObjectProcedure { + forEachClient(object : Consumer { private var first: Boolean = false - override fun execute(client: Client): Boolean { + override fun accept(client: Client) { try { val result = client.send>(messageId, if (first) message else message.duplicate()) first = false @@ -60,7 +60,6 @@ class ClientManager(private val listener: ClientListener?, val exceptionHandler: catch (e: Throwable) { exceptionHandler.exceptionCaught(e) } - return true } }) } @@ -87,9 +86,17 @@ class ClientManager(private val listener: ClientListener?, val exceptionHandler: return true } - fun forEachClient(procedure: TObjectProcedure) { + private fun forEachClient(procedure: Consumer) { synchronized (clients) { - clients.forEach(procedure) + for (client in clients) { + procedure.accept(client) + } + } + } + + fun findClient(predicate: Predicate): Client? { + synchronized (clients) { + return clients.firstOrNull { predicate.test(it) } } } } \ No newline at end of file diff --git a/platform/built-in-server/src/org/jetbrains/io/jsonRpc/JsonRpcServer.kt b/platform/built-in-server/src/org/jetbrains/io/jsonRpc/JsonRpcServer.kt index 0707c5ebca8a..54f69a9514a5 100644 --- a/platform/built-in-server/src/org/jetbrains/io/jsonRpc/JsonRpcServer.kt +++ b/platform/built-in-server/src/org/jetbrains/io/jsonRpc/JsonRpcServer.kt @@ -17,8 +17,8 @@ import com.intellij.util.Consumer import com.intellij.util.SmartList import com.intellij.util.io.releaseIfError import com.intellij.util.io.writeUtf8 -import gnu.trove.TIntArrayList import io.netty.buffer.* +import it.unimi.dsi.fastutil.ints.IntArrayList import org.jetbrains.annotations.TestOnly import org.jetbrains.concurrency.Promise import org.jetbrains.io.JsonReaderEx @@ -30,10 +30,10 @@ import java.util.concurrent.atomic.AtomicInteger private val LOG = Logger.getInstance(JsonRpcServer::class.java) private val INT_LIST_TYPE_ADAPTER_FACTORY = object : TypeAdapterFactory { - private var typeAdapter: IntArrayListTypeAdapter? = null + private var typeAdapter: IntArrayListTypeAdapter? = null override fun create(gson: Gson, type: TypeToken): TypeAdapter? { - if (type.type !== TIntArrayList::class.java) { + if (type.type !== IntArrayList::class.java) { return null } @@ -264,51 +264,55 @@ class JsonRpcServer(private val clientManager: ClientManager) : MessageServer { } // gson - SOE if param has type class com.intellij.openapi.editor.impl.DocumentImpl$MyCharArray, so, use hack - if (param is CharSequence) { - JsonUtil.escape(param, buffer) - } - else if (param == null) { - buffer.writeAscii("null") - } - else if (param is Boolean) { - buffer.writeAscii(param.toString()) - } - else if (param is Number) { - if (sb == null) { - sb = StringBuilder() + when (param) { + is CharSequence -> { + JsonUtil.escape(param, buffer) } - if (param is Int) { - sb.append(param.toInt()) + null -> { + buffer.writeAscii("null") } - else if (param is Long) { - sb.append(param.toLong()) + is Boolean -> { + buffer.writeAscii(param.toString()) } - else if (param is Float) { - sb.append(param.toFloat()) + is Number -> { + if (sb == null) { + sb = StringBuilder() + } + when (param) { + is Int -> { + sb.append(param.toInt()) + } + is Long -> { + sb.append(param.toLong()) + } + is Float -> { + sb.append(param.toFloat()) + } + is Double -> { + sb.append(param.toDouble()) + } + else -> { + sb.append(param.toString()) + } + } + buffer.writeAscii(sb) + sb.setLength(0) } - else if (param is Double) { - sb.append(param.toDouble()) + is Consumer<*> -> { + if (sb == null) { + sb = StringBuilder() + } + @Suppress("UNCHECKED_CAST") + (param as Consumer).consume(sb) + buffer.writeUtf8(sb) + sb.setLength(0) } - else { - sb.append(param.toString()) + else -> { + if (writer == null) { + writer = JsonWriter(ByteBufUtf8Writer(buffer)) + } + (gson.getAdapter(param.javaClass) as TypeAdapter).write(writer, param) } - buffer.writeAscii(sb) - sb.setLength(0) - } - else if (param is Consumer<*>) { - if (sb == null) { - sb = StringBuilder() - } - @Suppress("UNCHECKED_CAST") - (param as Consumer).consume(sb) - buffer.writeUtf8(sb) - sb.setLength(0) - } - else { - if (writer == null) { - writer = JsonWriter(ByteBufUtf8Writer(buffer)) - } - (gson.getAdapter(param.javaClass) as TypeAdapter).write(writer, param) } } } @@ -325,15 +329,14 @@ private class IntArrayListTypeAdapter : TypeAdapter() { override fun write(out: JsonWriter, value: T) { var error: IOException? = null out.beginArray() - (value as TIntArrayList).forEach { intValue -> + val iterator = (value as IntArrayList).iterator() + while (iterator.hasNext()) { try { - out.value(intValue.toLong()) + out.value(iterator.nextInt().toLong()) } catch (e: IOException) { error = e } - - error == null } error?.let { throw it } diff --git a/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java b/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java index 58e0cd676147..168b38c402bf 100644 --- a/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java +++ b/platform/core-impl/src/com/intellij/core/CoreFileTypeRegistry.java @@ -1,28 +1,13 @@ -/* - * Copyright 2000-2015 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. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.core; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeRegistry; import com.intellij.openapi.fileTypes.UnknownFileType; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.io.FileUtilRt; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.testFramework.LightVirtualFile; -import gnu.trove.THashMap; +import com.intellij.util.containers.CollectionFactory; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -34,8 +19,8 @@ import java.util.Map; /** * @author yole */ -public class CoreFileTypeRegistry extends FileTypeRegistry { - private final Map myExtensionsMap = new THashMap<>(FileUtil.PATH_HASHING_STRATEGY); +public final class CoreFileTypeRegistry extends FileTypeRegistry { + private final Map myExtensionsMap = CollectionFactory.createFilePathMap(); private final List myAllFileTypes = new ArrayList<>(); public CoreFileTypeRegistry() { @@ -67,8 +52,7 @@ public class CoreFileTypeRegistry extends FileTypeRegistry { @NotNull @Override public FileType getFileTypeByFileName(@NotNull @NonNls String fileName) { - final String extension = FileUtilRt.getExtension(fileName); - return getFileTypeByExtension(extension); + return getFileTypeByExtension(FileUtilRt.getExtension(fileName)); } @NotNull diff --git a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/TracingData.java b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/TracingData.java index 9086d0bc8647..b287854c99d7 100644 --- a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/TracingData.java +++ b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/TracingData.java @@ -2,20 +2,22 @@ package com.intellij.dupLocator.index; import com.intellij.dupLocator.util.PsiFragment; import com.intellij.openapi.util.ShutDownTracker; +import com.intellij.util.CommonProcessors; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.io.EnumeratorIntegerDescriptor; import com.intellij.util.io.PersistentHashMap; -import gnu.trove.TIntIntHashMap; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntListIterator; -import java.io.File; import java.io.IOException; -import java.util.List; +import java.nio.file.Paths; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -public class TracingData { +public final class TracingData { private static final String tracingDataLocation = "E:\\ultimate\\system\\occurrences"; private final PersistentHashMap keys; private final ScheduledThreadPoolExecutor pool = ConcurrencyUtil.newSingleScheduledThreadExecutor("My flushing thread"); @@ -37,14 +39,15 @@ public class TracingData { } }, 5, 5, TimeUnit.SECONDS); ShutDownTracker.getInstance().registerShutdownTask(() -> flushingFuture.cancel(false)); - } catch (IOException ex) { + } + catch (IOException ex) { ex.printStackTrace(); } keys = lkeys; } private static PersistentHashMap createOrOpenMap() throws IOException { - return new PersistentHashMap<>(new File(tracingDataLocation).toPath(), EnumeratorIntegerDescriptor.INSTANCE, + return new PersistentHashMap<>(Paths.get(tracingDataLocation), EnumeratorIntegerDescriptor.INSTANCE, EnumeratorIntegerDescriptor.INSTANCE); } @@ -65,25 +68,30 @@ public class TracingData { } currentMaxValue = maxValue.get(); } - } catch (IOException ex) { + } + catch (IOException ex) { ex.printStackTrace(); } } } public static void main(String[] args) throws IOException { - PersistentHashMap lkeys = createOrOpenMap(); - List mapping = (List)lkeys.getAllKeysWithExistingMapping(); + PersistentHashMap lKeys = createOrOpenMap(); + IntArrayList mapping = new IntArrayList(); + lKeys.processKeysWithExistingMapping(new CommonProcessors.CollectProcessor<>(mapping)); System.out.println(mapping.size()); - final TIntIntHashMap map = new TIntIntHashMap(mapping.size()); - for(Integer i:mapping) map.put(i, lkeys.get(i)); + Int2IntOpenHashMap map = new Int2IntOpenHashMap(mapping.size()); + for (IntListIterator iterator = mapping.iterator(); iterator.hasNext(); ) { + int i = iterator.nextInt(); + map.put(i, lKeys.get(i).intValue()); + } mapping.sort((o1, o2) -> map.get(o2) - map.get(o1)); for(int i = 0; i < 500; ++i) { //System.out.println(mapping.get(i) + ","); - System.out.println(mapping.get(i) + ":" + map.get(mapping.get(i))); + System.out.println(mapping.getInt(i) + ":" + map.get(mapping.getInt(i))); } - lkeys.close(); + lKeys.close(); } } diff --git a/platform/duplicates-analysis/src/com/intellij/dupLocator/treeHash/DuplocatorHashCallback.java b/platform/duplicates-analysis/src/com/intellij/dupLocator/treeHash/DuplocatorHashCallback.java index c40d10c37dd3..c81767d12347 100644 --- a/platform/duplicates-analysis/src/com/intellij/dupLocator/treeHash/DuplocatorHashCallback.java +++ b/platform/duplicates-analysis/src/com/intellij/dupLocator/treeHash/DuplocatorHashCallback.java @@ -1,6 +1,9 @@ package com.intellij.dupLocator.treeHash; -import com.intellij.dupLocator.*; +import com.intellij.dupLocator.DupInfo; +import com.intellij.dupLocator.DuplicatesProfile; +import com.intellij.dupLocator.DuplocatorState; +import com.intellij.dupLocator.NodeSpecificHasher; import com.intellij.dupLocator.util.DuplocatorUtil; import com.intellij.dupLocator.util.PsiFragment; import com.intellij.openapi.components.PathMacroManager; @@ -13,11 +16,13 @@ import com.intellij.psi.PsiDocumentManager; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.usageView.UsageInfo; +import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.xml.PrettyPrintWriter; import gnu.trove.TIntObjectHashMap; import gnu.trove.TIntObjectProcedure; -import gnu.trove.TObjectIntHashMap; -import gnu.trove.TObjectIntIterator; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; +import it.unimi.dsi.fastutil.objects.ObjectIterator; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,7 +32,7 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.*; -public class DuplocatorHashCallback implements FragmentsCollector { +public final class DuplocatorHashCallback implements FragmentsCollector { private static final Logger LOG = Logger.getInstance(DuplocatorHashCallback.class); private TIntObjectHashMap>> myDuplicates; @@ -41,7 +46,7 @@ public class DuplocatorHashCallback implements FragmentsCollector { myDiscardCost = discardCost; } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public DuplocatorHashCallback(final int bound, final int discardCost, final boolean readOnly) { this(bound, discardCost); myReadOnly = readOnly; @@ -51,7 +56,7 @@ public class DuplocatorHashCallback implements FragmentsCollector { this(lowerBound, 0); } - @SuppressWarnings({"UnusedDeclaration"}) + @SuppressWarnings("UnusedDeclaration") public void setReadOnly(final boolean readOnly) { myReadOnly = readOnly; } @@ -156,8 +161,7 @@ public class DuplocatorHashCallback implements FragmentsCollector { } public DupInfo getInfo() { - final TObjectIntHashMap duplicateList = new TObjectIntHashMap<>(); - + Object2IntOpenHashMap duplicateList = new Object2IntOpenHashMap<>(); myDuplicates.forEachEntry(new TIntObjectProcedure>>() { @Override public boolean execute(final int hash, final List> listList) { @@ -180,9 +184,9 @@ public class DuplocatorHashCallback implements FragmentsCollector { myDuplicates = null; - for (TObjectIntIterator dups = duplicateList.iterator(); dups.hasNext(); ) { - dups.advance(); - PsiFragment[] fragments = dups.key(); + for (ObjectIterator> iterator = duplicateList.object2IntEntrySet().fastIterator(); iterator.hasNext(); ) { + Object2IntMap.Entry entry = iterator.next(); + PsiFragment[] fragments = entry.getKey(); LOG.assertTrue(fragments.length > 1); boolean nested = false; for (PsiFragment fragment : fragments) { @@ -193,13 +197,12 @@ public class DuplocatorHashCallback implements FragmentsCollector { } if (nested) { - dups.remove(); + iterator.remove(); } } - final Object[] duplicates = duplicateList.keys(); - - Arrays.sort(duplicates, (x, y) -> ((PsiFragment[])y)[0].getCost() - ((PsiFragment[])x)[0].getCost()); + PsiFragment[][] duplicates = duplicateList.keySet().toArray(new PsiFragment[][]{}); + Arrays.sort(duplicates, (x, y) -> y[0].getCost() - x[0].getCost()); return new DupInfo() { private final TIntObjectHashMap myPattern2Description = new TIntObjectHashMap<>(); @@ -216,12 +219,12 @@ public class DuplocatorHashCallback implements FragmentsCollector { @Override public int getPatternDensity(int number) { - return ((PsiFragment[])duplicates[number]).length; + return duplicates[number].length; } @Override public PsiFragment[] getFragmentOccurences(int pattern) { - return (PsiFragment[])duplicates[pattern]; + return duplicates[pattern]; } @Override @@ -274,7 +277,6 @@ public class DuplocatorHashCallback implements FragmentsCollector { return null; } - @Override @Nullable public String getComment(int pattern) { @@ -289,7 +291,7 @@ public class DuplocatorHashCallback implements FragmentsCollector { @Override public int getHash(final int i) { - return duplicateList.get((PsiFragment[])duplicates[i]); + return duplicateList.getInt(duplicates[i]); } }; } @@ -298,7 +300,7 @@ public class DuplocatorHashCallback implements FragmentsCollector { int[] hashCodes = myDuplicates.keys(); //fragments try (BufferedWriter fileWriter = Files.newBufferedWriter(dir.resolve("fragments.xml"))) { - PrettyPrintWriter writer = new PrettyPrintWriter(fileWriter); + HierarchicalStreamWriter writer = new PrettyPrintWriter(fileWriter); writer.startNode("root"); for (int hash : hashCodes) { List> dupList = myDuplicates.get(hash); @@ -319,7 +321,7 @@ public class DuplocatorHashCallback implements FragmentsCollector { //duplicates public static void writeDuplicates(@NotNull Path dir, @NotNull Project project, DupInfo info) throws IOException { try (BufferedWriter fileWriter = Files.newBufferedWriter(dir.resolve("duplicates.xml"))) { - PrettyPrintWriter writer = new PrettyPrintWriter(fileWriter); + HierarchicalStreamWriter writer = new PrettyPrintWriter(fileWriter); writer.startNode("root"); final int patterns = info.getPatterns(); for (int i = 0; i < patterns; i++) { @@ -335,7 +337,7 @@ public class DuplocatorHashCallback implements FragmentsCollector { } private static void writeFragments(List psiFragments, - PrettyPrintWriter writer, + HierarchicalStreamWriter writer, @NotNull Project project, boolean shouldWriteOffsets) { final PathMacroManager macroManager = PathMacroManager.getInstance(project); diff --git a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/FontPreferencesImpl.java b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/FontPreferencesImpl.java index 48852400e2eb..7a6b364bb432 100644 --- a/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/FontPreferencesImpl.java +++ b/platform/editor-ui-ex/src/com/intellij/openapi/editor/colors/impl/FontPreferencesImpl.java @@ -1,11 +1,12 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.editor.colors.impl; import com.intellij.application.options.EditorFontsConstants; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.FontPreferences; import com.intellij.openapi.editor.colors.ModifiableFontPreferences; -import gnu.trove.TObjectIntHashMap; +import it.unimi.dsi.fastutil.objects.Object2IntMap; +import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -22,8 +23,7 @@ import java.util.List; * @author Denis Zhdanov */ public class FontPreferencesImpl extends ModifiableFontPreferences { - - @NotNull private final TObjectIntHashMap myFontSizes = new TObjectIntHashMap<>(); + @NotNull private final Object2IntMap myFontSizes = new Object2IntOpenHashMap<>(); @NotNull private final List myEffectiveFontFamilies = new ArrayList<>(); @NotNull private final List myRealFontFamilies = new ArrayList<>(); @@ -79,7 +79,7 @@ public class FontPreferencesImpl extends ModifiableFontPreferences { @Override public int getSize(@NotNull String fontFamily) { - int result = myFontSizes.get(fontFamily); + int result = myFontSizes.getInt(fontFamily); if (result <= 0) { result = myTemplateFontSize; } @@ -168,7 +168,7 @@ public class FontPreferencesImpl extends ModifiableFontPreferences { modifiablePreferences.resetFontSizes(); for (String fontFamily : myRealFontFamilies) { if (myFontSizes.containsKey(fontFamily)) { - modifiablePreferences.setFontSize(fontFamily, myFontSizes.get(fontFamily)); + modifiablePreferences.setFontSize(fontFamily, myFontSizes.getInt(fontFamily)); } } modifiablePreferences.setUseLigatures(myUseLigatures); @@ -217,7 +217,7 @@ public class FontPreferencesImpl extends ModifiableFontPreferences { if (!myRealFontFamilies.equals(that.myRealFontFamilies)) return false; for (String fontFamily : myRealFontFamilies) { - if (myFontSizes.get(fontFamily) != that.myFontSizes.get(fontFamily)) { + if (myFontSizes.getInt(fontFamily) != that.myFontSizes.getInt(fontFamily)) { return false; } } diff --git a/platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternSearcher.java b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternSearcher.java index b84481a079d5..04e8f5b61163 100644 --- a/platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternSearcher.java +++ b/platform/editor-ui-ex/src/com/intellij/psi/impl/search/IndexPatternSearcher.java @@ -1,5 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.impl.search; import com.intellij.lang.Language; @@ -28,7 +27,7 @@ import com.intellij.util.Processor; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.text.CharSequenceSubSequence; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -70,12 +69,12 @@ public class IndexPatternSearcher extends QueryExecutorBase commentRanges = findCommentTokenRanges(file, chars, queryParameters.getRange(), multiLine); - TIntArrayList occurrences = new TIntArrayList(1); + IntArrayList occurrences = new IntArrayList(1); IndexPattern[] patterns = patternProvider != null ? patternProvider.getIndexPatterns() : new IndexPattern[] {queryParameters.getPattern()}; for (int i = 0; i < commentRanges.size(); i++) { - occurrences.resetQuick(); + occurrences.clear(); for (int j = patterns.length - 1; j >=0; --j) { if (!collectPatternMatches(patterns, patterns[j], chars, commentRanges, i, file, queryParameters.getRange(), consumer, @@ -198,12 +197,12 @@ public class IndexPatternSearcher extends QueryExecutorBase commentRanges, + List commentRanges, int commentNum, PsiFile file, TextRange range, Processor consumer, - TIntArrayList matches, + IntArrayList matches, boolean multiLine ) { CommentRange commentRange = commentRanges.get(commentNum); @@ -229,7 +228,7 @@ public class IndexPatternSearcher extends QueryExecutorBase additionalRanges = multiLine ? findContinuation(start, chars, allIndexPatterns, commentRanges, commentNum) : Collections.emptyList(); if (range != null && !additionalRanges.isEmpty() && @@ -255,7 +254,7 @@ public class IndexPatternSearcher extends QueryExecutorBase findContinuation(int mainRangeStartOffset, CharSequence text, IndexPattern[] allIndexPatterns, - List commentRanges, int commentNum) { + List commentRanges, int commentNum) { CommentRange commentRange = commentRanges.get(commentNum); int lineStartOffset = CharArrayUtil.shiftBackwardUntil(text, mainRangeStartOffset - 1, "\n") + 1; int lineEndOffset = CharArrayUtil.shiftForwardUntil(text, mainRangeStartOffset, "\n"); @@ -292,7 +291,7 @@ public class IndexPatternSearcher extends QueryExecutorBase BY_START_OFFSET_THEN_BY_END_OFFSET = Comparator.comparingInt((CommentRange o) -> o.startOffset).thenComparingInt((CommentRange o) -> o.endOffset); diff --git a/platform/execution-impl/src/com/intellij/execution/impl/RunDashboardTypesPanel.kt b/platform/execution-impl/src/com/intellij/execution/impl/RunDashboardTypesPanel.kt index dee2677b8fb8..1821fdba9989 100644 --- a/platform/execution-impl/src/com/intellij/execution/impl/RunDashboardTypesPanel.kt +++ b/platform/execution-impl/src/com/intellij/execution/impl/RunDashboardTypesPanel.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.impl import com.intellij.execution.ExecutionBundle @@ -12,7 +12,6 @@ import com.intellij.ui.* import com.intellij.ui.components.JBList import com.intellij.ui.speedSearch.SpeedSearchUtil import com.intellij.util.containers.ContainerUtil -import gnu.trove.THashSet import org.jetbrains.annotations.NonNls import java.awt.BorderLayout import java.util.function.Consumer @@ -34,7 +33,7 @@ private val IGNORE_CASE_DISPLAY_NAME_COMPARATOR = Comparator */ internal class RunDashboardTypesPanel(private val myProject: Project) : JPanel(BorderLayout()) { private val listModel = CollectionListModel() - private val list = JBList(listModel) + private val list = JBList(listModel) init { val search = ListSpeedSearch(list) { it.displayName } @@ -116,7 +115,7 @@ internal class RunDashboardTypesPanel(private val myProject: Project) : JPanel(B }) } - fun isModified() = listModel.items.mapTo(THashSet()) { it.id } != RunDashboardManager.getInstance(myProject).types + fun isModified() = listModel.items.mapTo(HashSet()) { it.id } != RunDashboardManager.getInstance(myProject).types fun reset() { listModel.removeAll() @@ -127,7 +126,7 @@ internal class RunDashboardTypesPanel(private val myProject: Project) : JPanel(B fun apply() { val dashboardManager = RunDashboardManager.getInstance(myProject) - val types = listModel.items.mapTo(THashSet()) { it.id } + val types = listModel.items.mapTo(HashSet()) { it.id } if (types != dashboardManager.types) { dashboardManager.types = types } diff --git a/platform/execution-impl/src/com/intellij/execution/ui/RunContentManagerImpl.kt b/platform/execution-impl/src/com/intellij/execution/ui/RunContentManagerImpl.kt index 52e2210a8f25..1d533f040619 100644 --- a/platform/execution-impl/src/com/intellij/execution/ui/RunContentManagerImpl.kt +++ b/platform/execution-impl/src/com/intellij/execution/ui/RunContentManagerImpl.kt @@ -36,7 +36,6 @@ import com.intellij.util.ObjectUtils import com.intellij.util.SmartList import com.intellij.util.ui.EmptyIcon import com.intellij.util.ui.UIUtil -import gnu.trove.THashMap import org.jetbrains.annotations.ApiStatus import java.util.concurrent.ConcurrentLinkedDeque import java.util.function.Predicate @@ -46,7 +45,7 @@ private val EXECUTOR_KEY: Key = Key.create("Executor") private val CLOSE_LISTENER_KEY: Key = Key.create("CloseListener") class RunContentManagerImpl(private val project: Project) : RunContentManager { - private val toolWindowIdToBaseIcon: MutableMap = THashMap() + private val toolWindowIdToBaseIcon: MutableMap = HashMap() private val toolWindowIdZBuffer = ConcurrentLinkedDeque() init { diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java index 4834c35da0a5..6c05a10b6c60 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/model/execution/ExternalSystemTaskExecutionSettings.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.model.execution; import com.intellij.execution.configurations.ParametersList; @@ -7,7 +7,6 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.xmlb.annotations.Tag; -import gnu.trove.THashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -20,7 +19,6 @@ import java.util.*; */ @Tag("ExternalSystemSettings") public class ExternalSystemTaskExecutionSettings implements Cloneable { - @NotNull @NonNls public static final String TAG_NAME = "ExternalSystemSettings"; @NotNull @NonNls public static final Key JVM_AGENT_SETUP_KEY = Key.create("jvmAgentSetup"); @@ -55,7 +53,7 @@ public class ExternalSystemTaskExecutionSettings implements Cloneable { myTaskNames = ContainerUtil.copyList(source.myTaskNames); myTaskDescriptions = ContainerUtil.copyList(source.myTaskDescriptions); - myEnv = source.myEnv.isEmpty() ? Collections.emptyMap() : new THashMap<>(source.myEnv); + myEnv = source.myEnv.isEmpty() ? Collections.emptyMap() : new HashMap<>(source.myEnv); myPassParentEnvs = source.myPassParentEnvs; } diff --git a/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/AbstractExternalSystemLocalSettings.java b/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/AbstractExternalSystemLocalSettings.java index c54bb01cec1d..8977cac0f1a2 100644 --- a/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/AbstractExternalSystemLocalSettings.java +++ b/platform/external-system-api/src/com/intellij/openapi/externalSystem/settings/AbstractExternalSystemLocalSettings.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.settings; import com.intellij.openapi.components.StoragePathMacros; @@ -13,7 +13,7 @@ import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.project.Project; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; -import gnu.trove.THashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -188,10 +188,10 @@ public abstract class AbstractExternalSystemLocalSettings recentTasks = new SmartList<>(); - public Map> availableProjects = new THashMap<>(); - public Map modificationStamps = new THashMap<>(); - public Map projectBuildClasspath = new THashMap<>(); - public Map projectSyncType = new THashMap<>(); + public Map> availableProjects = new Object2ObjectOpenHashMap<>(); + public Map modificationStamps = new Object2ObjectOpenHashMap<>(); + public Map projectBuildClasspath = new Object2ObjectOpenHashMap<>(); + public Map projectSyncType = new Object2ObjectOpenHashMap<>(); } public enum SyncType { diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/autoimport/ProjectNotificationAware.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/autoimport/ProjectNotificationAware.kt index 2cf67fe8f4bd..99a3ad0f3415 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/autoimport/ProjectNotificationAware.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/autoimport/ProjectNotificationAware.kt @@ -1,20 +1,18 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.autoimport import com.intellij.openapi.Disposable import com.intellij.openapi.application.ApplicationManager import com.intellij.openapi.application.runInEdt -import com.intellij.openapi.components.ServiceManager +import com.intellij.openapi.components.service import com.intellij.openapi.diagnostic.Logger import com.intellij.openapi.externalSystem.model.ProjectSystemId import com.intellij.openapi.project.Project -import gnu.trove.THashSet import org.jetbrains.annotations.TestOnly class ProjectNotificationAware : Disposable { - private var isHidden = false - private val projectsWithNotification = THashSet() + private val projectsWithNotification = HashSet() fun notificationNotify(projectAware: ExternalSystemProjectAware) = runInEdt { val projectId = projectAware.projectId @@ -70,8 +68,6 @@ class ProjectNotificationAware : Disposable { private val LOG = Logger.getInstance("#com.intellij.openapi.externalSystem.autoimport") @JvmStatic - fun getInstance(project: Project): ProjectNotificationAware { - return ServiceManager.getService(project, ProjectNotificationAware::class.java) - } + fun getInstance(project: Project) = project.service() } } \ No newline at end of file diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt index 045573d7962f..99430e301eb7 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/configurationStore/ExternalSystemStreamProviderFactory.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.configurationStore import com.intellij.ProjectTopics @@ -14,7 +14,6 @@ import com.intellij.openapi.project.isExternalStorageEnabled import com.intellij.openapi.roots.ProjectModelElement import com.intellij.openapi.startup.StartupManager import com.intellij.util.Function -import gnu.trove.THashMap import org.jdom.Element import java.util.* import java.util.concurrent.atomic.AtomicBoolean @@ -30,7 +29,7 @@ internal class ExternalSystemStreamProviderFactory(private val project: Project) private val isReimportOnMissedExternalStorageScheduled = AtomicBoolean(false) private val storageSpecLock = ReentrantReadWriteLock() - private val storages = THashMap() + private val storages = HashMap() init { project.messageBus.connect().subscribe(ProjectTopics.MODULES, object : ModuleListener { diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java index 965048d7bc0a..2bb9afde2039 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/ContentRootDataService.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.service.project.manage; import com.intellij.ide.projectView.ProjectView; @@ -34,9 +34,11 @@ import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.MultiMap; -import gnu.trove.THashSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; +import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes; @@ -56,7 +58,7 @@ import static com.intellij.openapi.vfs.VfsUtilCore.pathToUrl; * @author Denis Zhdanov */ @Order(ExternalSystemConstants.BUILTIN_SERVICE_ORDER) -public class ContentRootDataService extends AbstractProjectDataService { +public final class ContentRootDataService extends AbstractProjectDataService { public static final com.intellij.openapi.util.Key CREATE_EMPTY_DIRECTORIES = com.intellij.openapi.util.Key.create("createEmptyDirectories"); @@ -87,7 +89,7 @@ public class ContentRootDataService extends AbstractProjectDataService modulesToExpand = new THashSet<>(); + Set modulesToExpand = new ObjectOpenHashSet<>(); MultiMap, DataNode> byModule = ExternalSystemApiUtil.groupBy(toImport, ModuleData.class); filterAndReportDuplicatingContentRoots(byModule, project); @@ -143,7 +145,7 @@ public class ContentRootDataService extends AbstractProjectDataService importedContentEntries = ContainerUtil.newIdentityTroveSet(); + final Set importedContentEntries = new ReferenceOpenHashSet<>(); for (final DataNode node : data) { final ContentRootData contentRoot = node.getData(); @@ -221,7 +223,7 @@ public class ContentRootDataService extends AbstractProjectDataService getSourceRoots(@NotNull ContentRootData contentRoot) { - Set sourceRoots = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); + Set sourceRoots = CollectionFactory.createFilePathSet(); for (ExternalSystemSourceType externalSrcType : ExternalSystemSourceType.values()) { final JpsModuleSourceRootType type = getJavaSourceRootType(externalSrcType); if (type == null) continue; @@ -432,11 +434,11 @@ public class ContentRootDataService extends AbstractProjectDataService myDuplicates = new ArrayList<>(); - public DuplicateModuleReport(@NotNull ModuleData original) { + private DuplicateModuleReport(@NotNull ModuleData original) { myOriginal = original; } diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerImpl.kt b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerImpl.kt index e2afef85b784..bdc9b08bc9df 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerImpl.kt +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/project/manage/SourceFolderManagerImpl.kt @@ -17,16 +17,15 @@ import com.intellij.openapi.project.Project import com.intellij.openapi.roots.ModuleRootModificationUtil import com.intellij.openapi.roots.SourceFolder import com.intellij.openapi.util.Disposer -import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.openapi.vfs.VirtualFileManager import com.intellij.openapi.vfs.newvfs.BulkFileListener import com.intellij.openapi.vfs.newvfs.events.VFileCreateEvent import com.intellij.openapi.vfs.newvfs.events.VFileEvent +import com.intellij.util.containers.CollectionFactory import com.intellij.util.containers.MultiMap -import gnu.trove.THashMap -import gnu.trove.THashSet +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import org.jetbrains.annotations.TestOnly import org.jetbrains.jps.model.java.JavaModuleSourceRootTypes import org.jetbrains.jps.model.java.JavaResourceRootType @@ -39,7 +38,7 @@ class SourceFolderManagerImpl(private val project: Project) : SourceFolderManage private var isDisposed = false private val mutex = Any() private var sourceFolders = PathPrefixTreeMap() - private var sourceFoldersByModule = THashMap() + private var sourceFoldersByModule = Object2ObjectOpenHashMap() override fun addSourceFolder(module: Module, url: String, type: JpsModuleSourceRootType<*>) { synchronized(mutex) { @@ -108,7 +107,7 @@ class SourceFolderManagerImpl(private val project: Project) : SourceFolderManage private data class ModuleModel( val module: Module, - val sourceFolders: MutableSet = THashSet(FileUtil.PATH_HASHING_STRATEGY) + val sourceFolders: MutableSet = CollectionFactory.createFilePathSet() ) init { @@ -144,7 +143,7 @@ class SourceFolderManagerImpl(private val project: Project) : SourceFolderManage moduleNamesToSourceFolderState.remove(module.name) } } - }); + }) } fun rescanAndUpdateSourceFolders() { @@ -206,7 +205,7 @@ class SourceFolderManagerImpl(private val project: Project) : SourceFolderManage return } sourceFolders = PathPrefixTreeMap() - sourceFoldersByModule = THashMap() + sourceFoldersByModule = Object2ObjectOpenHashMap() val moduleManager = ModuleManager.getInstance(project) diff --git a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/task/ui/ConfigureTasksActivationDialog.java b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/task/ui/ConfigureTasksActivationDialog.java index 5bf430075541..73055883b988 100644 --- a/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/task/ui/ConfigureTasksActivationDialog.java +++ b/platform/external-system-impl/src/com/intellij/openapi/externalSystem/service/task/ui/ConfigureTasksActivationDialog.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.service.task.ui; import com.intellij.icons.AllIcons; @@ -40,6 +40,7 @@ import com.intellij.util.ObjectUtils; import com.intellij.util.SmartList; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.SwingHelper; +import it.unimi.dsi.fastutil.objects.ReferenceOpenHashSet; import org.jdom.Element; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -317,7 +318,7 @@ public class ConfigureTasksActivationDialog extends DialogWrapper { } private void updateTree(@Nullable CachingSimpleNode nodeToUpdate) { - Set toUpdate = ContainerUtil.newIdentityTroveSet(); + Set toUpdate = new ReferenceOpenHashSet<>(); if (nodeToUpdate == null) { for (DefaultMutableTreeNode node : myTree.getSelectedNodes(DefaultMutableTreeNode.class, null)) { final Object userObject = node.getUserObject(); @@ -512,8 +513,7 @@ public class ConfigureTasksActivationDialog extends DialogWrapper { @Override public MyNode[] buildChildren() { - return ContainerUtil.map2Array(myTaskActivationState.getTasks(myPhase), MyNode.class, - taskName -> new TaskNode(taskName, this)); + return ContainerUtil.map2Array(myTaskActivationState.getTasks(myPhase), MyNode.class, taskName -> new TaskNode(taskName, this)); } @Override diff --git a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java index 66d33db87bac..712442583d3d 100644 --- a/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java +++ b/platform/external-system-impl/testSrc/com/intellij/openapi/externalSystem/test/ExternalSystemTestCase.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.openapi.externalSystem.test; import com.intellij.compiler.artifacts.ArtifactsTestUtil; @@ -39,9 +39,9 @@ import com.intellij.util.ArrayUtilRt; import com.intellij.util.ExceptionUtil; import com.intellij.util.PathUtil; import com.intellij.util.SmartList; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.io.PathKt; import com.intellij.util.io.TestFileSystemItem; -import gnu.trove.THashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.SystemIndependent; @@ -541,8 +541,8 @@ public abstract class ExternalSystemTestCase extends UsefulTestCase { } protected static void assertUnorderedPathsAreEqual(Collection actual, Collection expected) { - assertEquals(new SetWithToString<>(new THashSet<>(expected, FileUtil.PATH_HASHING_STRATEGY)), - new SetWithToString<>(new THashSet<>(actual, FileUtil.PATH_HASHING_STRATEGY))); + assertEquals(new SetWithToString<>(CollectionFactory.createFilePathSet(expected)), + new SetWithToString<>(CollectionFactory.createFilePathSet(actual))); } protected static void assertUnorderedElementsAreEqual(T[] actual, T... expected) { diff --git a/platform/indexing-api/src/com/intellij/psi/search/FilenameIndex.java b/platform/indexing-api/src/com/intellij/psi/search/FilenameIndex.java index 749c0a8d9ef4..a344a48f6e07 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/FilenameIndex.java +++ b/platform/indexing-api/src/com/intellij/psi/search/FilenameIndex.java @@ -15,7 +15,7 @@ import com.intellij.util.SmartList; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.ID; import com.intellij.util.indexing.IdFilter; -import gnu.trove.THashSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -27,13 +27,12 @@ import java.util.*; * @author yole */ public final class FilenameIndex { - @ApiStatus.Internal @NonNls public static final ID NAME = ID.create("FilenameIndex"); public static String @NotNull [] getAllFilenames(@Nullable Project project) { - Set names = new THashSet<>(); + Set names = new HashSet<>(); processAllFileNames((String s) -> { names.add(s); return true; @@ -115,7 +114,7 @@ public final class FilenameIndex { private static Set getVirtualFilesByNameIgnoringCase(@NotNull final String name, @NotNull final GlobalSearchScope scope, @Nullable final IdFilter idFilter) { - final Set keys = new THashSet<>(); + Set keys = new ObjectOpenHashSet<>(); processAllFileNames(value -> { if (name.equalsIgnoreCase(value)) { keys.add(value); @@ -124,7 +123,7 @@ public final class FilenameIndex { }, scope, idFilter); // values accessed outside of processAllKeys - final Set files = new THashSet<>(); + Set files = new ObjectOpenHashSet<>(); for (String each : keys) { files.addAll(getVirtualFilesByName(each, scope, idFilter)); } @@ -182,7 +181,7 @@ public final class FilenameIndex { private static Collection getVirtualFilesByName(@NotNull String name, @NotNull GlobalSearchScope scope, IdFilter filter) { - Set files = new THashSet<>(); + Set files = new ObjectOpenHashSet<>(); FileBasedIndex.getInstance().processValues(NAME, name, null, (file, value) -> { files.add(file); return true; diff --git a/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java b/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java index 5c40815210fb..6974ecb28b50 100644 --- a/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java +++ b/platform/indexing-api/src/com/intellij/psi/search/searches/DefinitionsScopedSearch.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.psi.search.searches; @@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull; * have been searched and class inheritors for the class. * */ -public class DefinitionsScopedSearch extends ExtensibleQueryFactory { +public final class DefinitionsScopedSearch extends ExtensibleQueryFactory { public static final ExtensionPointName> EP_NAME = ExtensionPointName.create("com.intellij.definitionsScopedSearch"); public static final DefinitionsScopedSearch INSTANCE = new DefinitionsScopedSearch(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/HintsBuffer.kt b/platform/lang-impl/src/com/intellij/codeInsight/hints/HintsBuffer.kt index f5352bc6de45..f4ec35dbb426 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/HintsBuffer.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/HintsBuffer.kt @@ -2,37 +2,40 @@ package com.intellij.codeInsight.hints import com.intellij.openapi.editor.Inlay -import gnu.trove.TIntHashSet -import gnu.trove.TIntObjectHashMap +import it.unimi.dsi.fastutil.ints.Int2ObjectMap +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap +import it.unimi.dsi.fastutil.ints.IntSet /** * Utility class to accumulate hints. Non thread-safe. */ class HintsBuffer { - val inlineHints = TIntObjectHashMap>>() - val blockBelowHints = TIntObjectHashMap>>() - val blockAboveHints = TIntObjectHashMap>>() + val inlineHints = Int2ObjectOpenHashMap>>() + internal val blockBelowHints = Int2ObjectOpenHashMap>>() + internal val blockAboveHints = Int2ObjectOpenHashMap>>() - fun mergeIntoThis(another: HintsBuffer) { - inlineHints.mergeIntoThis(another.inlineHints) - blockBelowHints.mergeIntoThis(another.blockBelowHints) - blockAboveHints.mergeIntoThis(another.blockAboveHints) + internal fun mergeIntoThis(another: HintsBuffer) { + mergeIntoThis(inlineHints, another.inlineHints) + mergeIntoThis(blockBelowHints, another.blockBelowHints) + mergeIntoThis(blockAboveHints, another.blockAboveHints) } /** * Counts all offsets of given [placement] which are not inside [other] */ - fun countDisjointElements(other: TIntHashSet, placement: Inlay.Placement): Int { + internal fun countDisjointElements(other: IntSet, placement: Inlay.Placement): Int { val map = getMap(placement) var count = 0 - map.forEachKey { - if (it !in other) count++ - true + val iterator = map.keys.iterator() + while (iterator.hasNext()) { + if (!other.contains(iterator.nextInt())) { + count++ + } } return count } - fun contains(offset: Int, placement: Inlay.Placement): Boolean { + internal fun contains(offset: Int, placement: Inlay.Placement): Boolean { return getMap(placement).contains(offset) } @@ -41,24 +44,27 @@ class HintsBuffer { } @Suppress("UNCHECKED_CAST") - private fun getMap(placement: Inlay.Placement) : TIntObjectHashMap>> { + private fun getMap(placement: Inlay.Placement) : Int2ObjectMap>> { return when (placement) { Inlay.Placement.INLINE -> inlineHints Inlay.Placement.ABOVE_LINE -> blockAboveHints Inlay.Placement.BELOW_LINE -> blockBelowHints Inlay.Placement.AFTER_LINE_END -> TODO() - } as TIntObjectHashMap>> + } as Int2ObjectOpenHashMap>> } } -fun TIntObjectHashMap>.mergeIntoThis(another: TIntObjectHashMap>) { - another.forEachEntry { otherOffset, otherList -> - val current = this[otherOffset] +private fun mergeIntoThis(one: Int2ObjectOpenHashMap>, another: Int2ObjectOpenHashMap>) { + val bIterator = another.int2ObjectEntrySet().fastIterator() + while (bIterator.hasNext()) { + val otherEntry = bIterator.next() + val otherOffset = otherEntry.intKey + val current = one.get(otherOffset) if (current == null) { - put(otherOffset, otherList) - } else { - current.addAll(otherList) + one.put(otherOffset, otherEntry.value) + } + else { + current.addAll(otherEntry.value) } - true } } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt b/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt index 5ba8d878770a..1e249059932e 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsPass.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.codeInsight.hints import com.intellij.codeHighlighting.EditorBoundHighlightingPass @@ -16,12 +16,12 @@ import com.intellij.openapi.util.Key import com.intellij.psi.PsiElement import com.intellij.psi.SyntaxTraverser import com.intellij.util.Processor -import gnu.trove.TIntHashSet -import gnu.trove.TIntObjectHashMap +import it.unimi.dsi.fastutil.ints.Int2ObjectMap +import it.unimi.dsi.fastutil.ints.Int2ObjectMaps +import it.unimi.dsi.fastutil.ints.IntOpenHashSet import java.util.concurrent.ConcurrentLinkedQueue import java.util.stream.IntStream - class InlayHintsPass( private val rootElement: PsiElement, private val enabledCollectors: List>, @@ -113,32 +113,32 @@ class InlayHintsPass( } - private fun addInlineHints(hints: HintsBuffer, - inlayModel: InlayModel) { - hints.inlineHints.forEachEntry { offset, presentations -> - val renderer = InlineInlayRenderer(presentations) - val inlay = inlayModel.addInlineElement(offset, renderer) ?: return@forEachEntry false + private fun addInlineHints(hints: HintsBuffer, inlayModel: InlayModel) { + for (entry in Int2ObjectMaps.fastIterable(hints.inlineHints)) { + val renderer = InlineInlayRenderer(entry.value) + val inlay = inlayModel.addInlineElement(entry.intKey, renderer) ?: break postprocessInlay(inlay) - true } } private fun addBlockHints(inlayModel: InlayModel, - map: TIntObjectHashMap>>, + map: Int2ObjectMap>>, showAbove: Boolean ) { - map.forEachEntry { offset, presentations -> - val renderer = BlockInlayRenderer(presentations) + for (entry in Int2ObjectMaps.fastIterable(map)) { + val presentations = entry.value val constraints = presentations.first().constraints val inlay = inlayModel.addBlockElement( - offset, + entry.intKey, constraints?.relatesToPrecedingText ?: true, showAbove, constraints?.priority ?: 0, - renderer - ) ?: return@forEachEntry false + BlockInlayRenderer(presentations) + ) ?: break postprocessInlay(inlay) - showAbove + if (!showAbove) { + break + } } } @@ -182,11 +182,9 @@ class InlayHintsPass( /** * Estimates count of changes (removal, addition) for inlays */ - fun estimateChangesCountForPlacement(existingInlayOffsets: IntStream, - collected: HintsBuffer, - placement: Inlay.Placement): Int { + fun estimateChangesCountForPlacement(existingInlayOffsets: IntStream, collected: HintsBuffer, placement: Inlay.Placement): Int { var count = 0 - val offsetsWithExistingHints = TIntHashSet() + val offsetsWithExistingHints = IntOpenHashSet() for (offset in existingInlayOffsets) { if (!collected.contains(offset, placement)) { count++ diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsSinkImpl.kt b/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsSinkImpl.kt index f514a2e29735..854d1a6caa3d 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsSinkImpl.kt +++ b/platform/lang-impl/src/com/intellij/codeInsight/hints/InlayHintsSinkImpl.kt @@ -7,7 +7,8 @@ import com.intellij.codeInsight.hints.presentation.RootInlayPresentation import com.intellij.openapi.editor.Document import com.intellij.openapi.editor.Editor import com.intellij.util.SmartList -import gnu.trove.TIntObjectHashMap +import it.unimi.dsi.fastutil.ints.Int2ObjectMap +import java.util.function.IntFunction class InlayHintsSinkImpl(val editor: Editor) : InlayHintsSink { private val buffer = HintsBuffer() @@ -18,7 +19,7 @@ class InlayHintsSinkImpl(val editor: Editor) : InlayHintsSink { } override fun addInlineElement(offset: Int, presentation: RootInlayPresentation<*>, constraints: HorizontalConstraints?) { - buffer.inlineHints.addCreatingListIfNeeded(offset, HorizontalConstrainedPresentation(presentation, constraints)) + addCreatingListIfNeeded(buffer.inlineHints, offset, HorizontalConstrainedPresentation(presentation, constraints)) } override fun addBlockElement(offset: Int, @@ -37,24 +38,14 @@ class InlayHintsSinkImpl(val editor: Editor) : InlayHintsSink { constraints: BlockConstraints?) { val map = if (showAbove) buffer.blockAboveHints else buffer.blockBelowHints val offset = document.getLineStartOffset(logicalLine) - map.addCreatingListIfNeeded(offset, BlockConstrainedPresentation(presentation, constraints)) + addCreatingListIfNeeded(map, offset, BlockConstrainedPresentation(presentation, constraints)) } internal fun complete(): HintsBuffer { return buffer } +} - companion object { - private fun TIntObjectHashMap>>.addCreatingListIfNeeded( - offset: Int, - value: ConstrainedPresentation<*, T> - ) { - var list = this[offset] - if (list == null) { - list = SmartList() - put(offset, list) - } - list.add(value) - } - } +private fun addCreatingListIfNeeded(map: Int2ObjectMap>>, offset: Int, value: ConstrainedPresentation<*, T>) { + map.computeIfAbsent(offset, IntFunction { SmartList>() }).add(value) } \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerSettings.java b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerSettings.java index 19f8758afda6..478db3eb1647 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerSettings.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/intention/impl/config/IntentionManagerSettings.java @@ -18,7 +18,7 @@ import com.intellij.openapi.extensions.PluginDescriptor; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.containers.Interner; -import com.intellij.util.containers.WeakStringInterner; +import com.intellij.util.containers.WeakInterner; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -33,7 +33,7 @@ public final class IntentionManagerSettings implements PersistentStateComponent< private static final Logger LOG = Logger.getInstance(IntentionManagerSettings.class); private static final class MetaDataKey extends Pair { - private static final Interner ourInterner = new WeakStringInterner(); + private static final Interner ourInterner = WeakInterner.createWeakInterner(); private MetaDataKey(String @NotNull [] categoryNames, @NotNull final String familyName) { super(StringUtil.join(categoryNames, ":"), ourInterner.intern(familyName)); } diff --git a/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java b/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java index e23461448a4e..da4071c6db8f 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/ui/ProblemDescriptionNode.java @@ -1,5 +1,4 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - package com.intellij.codeInspection.ui; import com.intellij.codeHighlighting.HighlightDisplayLevel; @@ -18,7 +17,6 @@ import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.psi.PsiElement; import com.intellij.util.ObjectUtils; import com.intellij.util.containers.Interner; -import com.intellij.util.containers.WeakStringInterner; import com.intellij.xml.util.XmlStringUtil; import gnu.trove.TObjectIntHashMap; import org.jetbrains.annotations.NotNull; @@ -106,7 +104,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode { } @NotNull - public InspectionToolWrapper getToolWrapper() { + public InspectionToolWrapper getToolWrapper() { return getPresentation().getToolWrapper(); } @@ -161,7 +159,7 @@ public class ProblemDescriptionNode extends SuppressableInspectionTreeNode { return descriptor != null && getPresentation().isExcluded(descriptor); } - private static final Interner NAME_INTERNER = new WeakStringInterner(); + private static final Interner NAME_INTERNER = Interner.createWeakInterner(); @NotNull @Override diff --git a/platform/lang-impl/src/com/intellij/execution/console/PrefixHistoryModel.kt b/platform/lang-impl/src/com/intellij/execution/console/PrefixHistoryModel.kt index 3c8167055b4c..342a423bacff 100644 --- a/platform/lang-impl/src/com/intellij/execution/console/PrefixHistoryModel.kt +++ b/platform/lang-impl/src/com/intellij/execution/console/PrefixHistoryModel.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.execution.console import com.intellij.execution.console.ConsoleHistoryModel.Entry @@ -9,12 +9,11 @@ import com.intellij.openapi.util.SimpleModificationTracker import com.intellij.openapi.util.TextRange import com.intellij.util.containers.ConcurrentFactoryMap import com.intellij.util.containers.ContainerUtil -import gnu.trove.TIntStack +import it.unimi.dsi.fastutil.ints.IntArrayList /** * @author Yuli Fiterman */ - private val MasterModels = ConcurrentFactoryMap.create( { MasterModel() @@ -22,10 +21,8 @@ private val MasterModels = ConcurrentFactoryMap.create( ContainerUtil.createConcurrentWeakValueMap() }) - private fun assertWriteThread() = ApplicationManager.getApplication().assertIsWriteThread() - fun createModel(persistenceId: String, console: LanguageConsoleView): ConsoleHistoryModel { val masterModel: MasterModel = MasterModels[persistenceId]!! fun getPrefixFromConsole(): String { @@ -46,7 +43,7 @@ private class PrefixHistoryModel constructor(private val masterModel: MasterMode private var currentIndex: Int? = null private var currentEntries: List? = null - private var prevEntries: TIntStack = TIntStack() + private var prevEntries = IntArrayList() private var historyPrefix: String = "" init { @@ -104,8 +101,8 @@ private class PrefixHistoryModel constructor(private val masterModel: MasterMode override fun getHistoryPrev(): Entry? { val entries = currentEntries ?: return null - return if (prevEntries.size() > 0) { - val index = prevEntries.pop() + return if (prevEntries.size > 0) { + val index = prevEntries.popInt() currentIndex = index createEntry(entries[index]) } @@ -154,7 +151,7 @@ private class MasterModel(private val modTracker: SimpleModificationTracker = Si override fun getMaxHistorySize() = UISettings.instance.state.consoleCommandHistoryLimit - override fun isEmpty(): Boolean = entries.isEmpty() + override fun isEmpty() = entries.isEmpty() - override fun getHistorySize(): Int = entries.size + override fun getHistorySize() = entries.size } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java index 34c357e5a365..07d763d9d258 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/impl/ProjectRootManagerComponent.java @@ -34,13 +34,14 @@ import com.intellij.project.ProjectKt; import com.intellij.ui.GuiUtils; import com.intellij.util.ConcurrencyUtil; import com.intellij.util.concurrency.AppExecutorUtil; +import com.intellij.util.containers.CollectionFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.indexing.FileBasedIndexImpl; import com.intellij.util.indexing.FileBasedIndexProjectHandler; import com.intellij.util.indexing.UnindexedFilesUpdater; import com.intellij.util.messages.MessageBusConnection; -import gnu.trove.THashSet; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.CalledInAwt; import org.jetbrains.annotations.NotNull; @@ -70,7 +71,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen private boolean myPointerChangesDetected; private int myInsideRefresh; - private @NotNull Set myRootsToWatch = new THashSet<>(); + private @NotNull Set myRootsToWatch = new ObjectOpenHashSet<>(); private Disposable myRootPointersDisposable = Disposer.newDisposable(); // accessed in EDT public ProjectRootManagerComponent(@NotNull Project project) { @@ -213,8 +214,8 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen private @NotNull Pair, Set> collectWatchRoots(@NotNull Disposable disposable) { ApplicationManager.getApplication().assertReadAccessAllowed(); - Set recursivePaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); - Set flatPaths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); + Set recursivePaths = CollectionFactory.createFilePathSet(); + Set flatPaths = CollectionFactory.createFilePathSet(); String projectFilePath = myProject.getProjectFilePath(); if (projectFilePath != null && !Project.DIRECTORY_STORE_FOLDER.equals(new File(projectFilePath).getParentFile().getName())) { @@ -240,7 +241,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen } List recursiveUrls = ContainerUtil.map(recursivePaths, VfsUtilCore::pathToUrl); - Set excludedUrls = new THashSet<>(); + Set excludedUrls = new ObjectOpenHashSet<>(); // changes in files provided by this method should be watched manually because no-one's bothered to set up correct pointers for them for (DirectoryIndexExcludePolicy excludePolicy : DirectoryIndexExcludePolicy.EP_NAME.getExtensions(myProject)) { Collections.addAll(excludedUrls, excludePolicy.getExcludeUrlsForProject()); @@ -265,7 +266,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen } private void collectModuleWatchRoots(@NotNull Set recursivePaths, @NotNull Set flatPaths) { - Set urls = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); + Set urls = CollectionFactory.createFilePathSet(); for (Module module : ModuleManager.getInstance(myProject).getModules()) { ModuleRootManager rootManager = ModuleRootManager.getInstance(module); @@ -332,7 +333,7 @@ public class ProjectRootManagerComponent extends ProjectRootManagerImpl implemen @Override public void markRootsForRefresh() { - Set paths = new THashSet<>(FileUtil.PATH_HASHING_STRATEGY); + Set paths = CollectionFactory.createFilePathSet(); collectModuleWatchRoots(paths, paths); LocalFileSystem fs = LocalFileSystem.getInstance(); diff --git a/platform/platform-util-io/src/com/intellij/execution/process/OSProcessHandler.java b/platform/platform-util-io/src/com/intellij/execution/process/OSProcessHandler.java index f477123752a4..061b10c67391 100644 --- a/platform/platform-util-io/src/com/intellij/execution/process/OSProcessHandler.java +++ b/platform/platform-util-io/src/com/intellij/execution/process/OSProcessHandler.java @@ -19,7 +19,6 @@ import com.intellij.util.ExceptionUtil; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.BaseDataReader; import com.intellij.util.io.BaseOutputReader; -import gnu.trove.THashSet; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -27,6 +26,7 @@ import org.jetbrains.annotations.Nullable; import java.io.File; import java.io.InputStream; import java.nio.charset.Charset; +import java.util.HashSet; import java.util.Set; public class OSProcessHandler extends BaseOSProcessHandler { @@ -297,7 +297,7 @@ public class OSProcessHandler extends BaseOSProcessHandler { public static void deleteFileOnTermination(@NotNull GeneralCommandLine commandLine, @NotNull File fileToDelete) { Set set = commandLine.getUserData(DELETE_FILES_ON_TERMINATION); if (set == null) { - set = new THashSet<>(); + set = new HashSet<>(); commandLine.putUserData(DELETE_FILES_ON_TERMINATION, set); } set.add(fileToDelete); diff --git a/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java b/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java index f3193f72a560..61061aad07f5 100644 --- a/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java +++ b/platform/platform-util-io/src/com/intellij/execution/process/impl/ProcessListUtil.java @@ -15,7 +15,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.NullableFunction; import com.intellij.util.PathUtil; -import gnu.trove.TIntObjectHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -163,7 +163,7 @@ public final class ProcessListUtil { List fulls = doParseMacOutput(full); if (commands == null || fulls == null) return null; - TIntObjectHashMap idToCommand = new TIntObjectHashMap<>(); + Int2ObjectOpenHashMap idToCommand = new Int2ObjectOpenHashMap<>(); for (MacProcessInfo each : commands) { idToCommand.put(each.pid, each.commandLine); } @@ -188,7 +188,7 @@ public final class ProcessListUtil { List fulls = doParseMacOutput(full); if (commands == null || fulls == null) return null; - TIntObjectHashMap idToCommand = new TIntObjectHashMap<>(); + Int2ObjectOpenHashMap idToCommand = new Int2ObjectOpenHashMap<>(); for (MacProcessInfo each : commands) { idToCommand.put(each.pid, each.commandLine); } diff --git a/platform/platform-util-io/src/com/intellij/util/Urls.kt b/platform/platform-util-io/src/com/intellij/util/Urls.kt index 3772184ebb8c..8549fb7c657c 100644 --- a/platform/platform-util-io/src/com/intellij/util/Urls.kt +++ b/platform/platform-util-io/src/com/intellij/util/Urls.kt @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util import com.intellij.openapi.diagnostic.logger @@ -10,7 +10,6 @@ import com.intellij.openapi.vfs.StandardFileSystems import com.intellij.openapi.vfs.VfsUtilCore import com.intellij.openapi.vfs.VirtualFile import com.intellij.util.io.URLUtil -import gnu.trove.TObjectHashingStrategy import java.net.MalformedURLException import java.net.URI import java.net.URISyntaxException @@ -20,8 +19,6 @@ import java.util.regex.Pattern private val URI_PATTERN = Pattern.compile("^([^:/?#]+):(//)?([^/?#]*)([^?#;]*)(.*)") object Urls { - val caseInsensitiveUrlHashingStrategy: TObjectHashingStrategy by lazy { CaseInsensitiveUrlHashingStrategy() } - @JvmStatic fun newUri(scheme: String?, path: String): Url = UrlImpl(scheme, null, path) @@ -83,8 +80,8 @@ object Urls { // java.net.URI.create cannot parse "file:///Test Stuff" - but you don't need to worry about it - this method is aware @JvmStatic fun parseFromIdea(url: CharSequence): Url? { - for (i in 0 until url.length) { - when (url[i]) { + for (element in url) { + when (element) { ':' -> return parseUrl(url) // file:// or dart:core/foo '/', '\\' -> return newLocalFileUrl(url.toString()) } @@ -185,9 +182,4 @@ object Urls { catch (e: URISyntaxException) { throw RuntimeException(e) } -} - -private class CaseInsensitiveUrlHashingStrategy : TObjectHashingStrategy { - override fun computeHashCode(url: Url?) = url?.hashCodeCaseInsensitive() ?: 0 - override fun equals(url1: Url, url2: Url) = Urls.equals(url1, url2, caseSensitive = false, ignoreParameters = false) } \ No newline at end of file diff --git a/platform/platform-util-io/src/org/jetbrains/io/FileResponses.kt b/platform/platform-util-io/src/org/jetbrains/io/FileResponses.kt index 323292125b14..2d87cbdd5d9b 100644 --- a/platform/platform-util-io/src/org/jetbrains/io/FileResponses.kt +++ b/platform/platform-util-io/src/org/jetbrains/io/FileResponses.kt @@ -1,15 +1,15 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package org.jetbrains.io import com.intellij.openapi.diagnostic.logger import com.intellij.util.PathUtilRt -import gnu.trove.THashMap import io.netty.channel.Channel import io.netty.channel.ChannelFutureListener import io.netty.channel.DefaultFileRegion import io.netty.handler.codec.http.* import io.netty.handler.ssl.SslHandler import io.netty.handler.stream.ChunkedNioFile +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap import java.nio.channels.FileChannel import java.nio.file.Files import java.nio.file.NoSuchFileException @@ -26,7 +26,7 @@ fun flushChunkedResponse(channel: Channel, isKeepAlive: Boolean) { } private val fileExtToMimeType by lazy { - val map = THashMap(1100) + val map = Object2ObjectOpenHashMap(1100) FileResponses.javaClass.getResourceAsStream("/mime-types.csv").bufferedReader().useLines { for (line in it) { if (line.isBlank()) { diff --git a/platform/structure-view-impl/src/com/intellij/ide/util/treeView/smartTree/CachingChildrenTreeNode.java b/platform/structure-view-impl/src/com/intellij/ide/util/treeView/smartTree/CachingChildrenTreeNode.java index f3eecfa5f631..cf06b808602e 100644 --- a/platform/structure-view-impl/src/com/intellij/ide/util/treeView/smartTree/CachingChildrenTreeNode.java +++ b/platform/structure-view-impl/src/com/intellij/ide/util/treeView/smartTree/CachingChildrenTreeNode.java @@ -1,5 +1,4 @@ // Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. - package com.intellij.ide.util.treeView.smartTree; import com.intellij.ide.structureView.impl.StructureViewElementWrapper; @@ -10,7 +9,7 @@ import com.intellij.openapi.project.IndexNotReadyException; import com.intellij.openapi.project.Project; import com.intellij.pom.Navigatable; import com.intellij.util.containers.JBIterable; -import gnu.trove.THashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -77,8 +76,10 @@ public abstract class CachingChildrenTreeNode extends AbstractTreeNode extends AbstractTreeNode> ungrouped = new ArrayList<>(); + List> ungrouped = new ArrayList<>(); Collection> children = getChildren(); for (AbstractTreeNode child : children) { if (child instanceof TreeElementWrapper) { @@ -189,7 +190,7 @@ public abstract class CachingChildrenTreeNode extends AbstractTreeNode createGroupNodes(@NotNull Collection groups) { - Map result = new THashMap<>(); + Map result = new Object2ObjectOpenHashMap<>(groups.size()); for (Group group : groups) { result.put(group, createGroupWrapper(getProject(), group, myTreeModel)); } diff --git a/platform/util/src/com/intellij/util/io/PersistentHashMap.java b/platform/util/src/com/intellij/util/io/PersistentHashMap.java index 582a9abb3466..48ea436cec92 100644 --- a/platform/util/src/com/intellij/util/io/PersistentHashMap.java +++ b/platform/util/src/com/intellij/util/io/PersistentHashMap.java @@ -1,4 +1,4 @@ -// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. +// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file. package com.intellij.util.io; import com.intellij.openapi.diagnostic.Logger; @@ -576,7 +576,7 @@ public class PersistentHashMap implements AppendablePersistentMap processor) throws IOException { + public final boolean processKeysWithExistingMapping(@NotNull Processor processor) throws IOException { synchronized (getDataAccessLock()) { try { if (myAppendCache != null) {