cleanup, migrate from trove int collections to fastutil

GitOrigin-RevId: b23aafcf94ac76c8fd88d022c32ecac6a33a0be9
This commit is contained in:
Vladimir Krivosheev
2020-05-29 11:29:15 +03:00
committed by intellij-monorepo-bot
parent af751408e2
commit ae0f480588
11 changed files with 71 additions and 59 deletions
@@ -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.compiler;
import com.intellij.ProjectTopics;
@@ -26,11 +26,11 @@ import com.intellij.packaging.impl.compiler.ArtifactCompileScope;
import com.intellij.pom.java.LanguageLevel;
import com.intellij.testFramework.*;
import com.intellij.util.concurrency.Semaphore;
import com.intellij.util.containers.CollectionFactory;
import com.intellij.util.io.DirectoryContentSpec;
import com.intellij.util.io.DirectoryContentSpecKt;
import com.intellij.util.io.TestFileSystemBuilder;
import com.intellij.util.ui.UIUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jps.util.JpsPathUtil;
@@ -399,7 +399,7 @@ public abstract class BaseCompilerTestCase extends JavaModuleTestCase {
myExternalBuildUpToDate = externalBuildUpToDate;
myErrors = errors;
myWarnings = warnings;
myGeneratedPaths = new THashSet<>(generatedFilePaths, FileUtil.PATH_HASHING_STRATEGY);
myGeneratedPaths = CollectionFactory.createFilePathSet(generatedFilePaths);
}
public void assertUpToDate() {
@@ -1,16 +1,17 @@
// 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.compiler;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.vfs.encoding.EncodingProjectManager;
import com.intellij.testFramework.JavaPsiTestCase;
import com.intellij.testFramework.PsiTestUtil;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
public class CompilerEncodingServiceTest extends JavaPsiTestCase {
@@ -18,7 +19,7 @@ public class CompilerEncodingServiceTest extends JavaPsiTestCase {
private static final Charset WINDOWS_1252 = Charset.forName("windows-1252");
private Collection<Charset> projectDefaultPlus(Charset @NotNull ... charsets) {
Set<Charset> result = new THashSet<>();
Set<Charset> result = new HashSet<>();
result.add(getProjectDefault());
result.addAll(Arrays.asList(charsets));
return result;
@@ -1,3 +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.compiler.artifacts;
import com.intellij.openapi.util.text.StringUtil;
@@ -8,14 +9,10 @@ import com.intellij.packaging.elements.PackagingElement;
import com.intellij.packaging.impl.ui.ArtifactProblemsHolderBase;
import com.intellij.packaging.ui.ArtifactProblemQuickFix;
import com.intellij.util.containers.ContainerUtil;
import gnu.trove.THashMap;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.*;
public abstract class PackagingValidationTestCase extends PackagingElementsTestCase {
protected PackagingValidationTestCase() {
@@ -32,7 +29,7 @@ public abstract class PackagingValidationTestCase extends PackagingElementsTestC
protected class MockArtifactProblemsHolder extends ArtifactProblemsHolderBase {
private final List<String> myProblems = new ArrayList<>();
private final Map<String, ArtifactProblemQuickFix[]> myQuickFixes = new THashMap<>();
private final Map<String, ArtifactProblemQuickFix[]> myQuickFixes = new HashMap<>();
public MockArtifactProblemsHolder() {
super(new MockPackagingEditorContext(new MockArtifactsStructureConfigurableContext(), null));
@@ -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.ide.util.frameworkSupport;
import com.intellij.framework.FrameworkTypeEx;
@@ -10,7 +9,7 @@ import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleType;
import com.intellij.openapi.roots.ui.configuration.FacetsProvider;
import com.intellij.openapi.util.Couple;
import com.intellij.openapi.util.Pair;
import com.intellij.util.graph.CachingSemiGraph;
import com.intellij.util.graph.DFSTBuilder;
import com.intellij.util.graph.GraphGenerator;
@@ -20,7 +19,7 @@ import org.jetbrains.annotations.Nullable;
import java.util.*;
public class FrameworkSupportUtil {
public final class FrameworkSupportUtil {
private static final Logger LOG = Logger.getInstance(FrameworkSupportUtil.class);
private FrameworkSupportUtil() {
@@ -38,7 +37,7 @@ public class FrameworkSupportUtil {
@Nullable Module module,
@NotNull FacetsProvider facetsProvider) {
List<FrameworkSupportInModuleProvider> allProviders = getAllProviders();
ArrayList<FrameworkSupportInModuleProvider> result = new ArrayList<>();
List<FrameworkSupportInModuleProvider> result = new ArrayList<>();
for (FrameworkSupportInModuleProvider provider : allProviders) {
if (provider.isEnabledForModuleType(moduleType) && (module == null || provider.canAddSupport(module, facetsProvider))) {
result.add(provider);
@@ -82,7 +81,7 @@ public class FrameworkSupportUtil {
DFSTBuilder<FrameworkSupportInModuleProvider>
builder = new DFSTBuilder<>(GraphGenerator.generate(CachingSemiGraph.cache(new ProvidersGraph(types))));
if (!builder.isAcyclic()) {
Couple<FrameworkSupportInModuleProvider> pair = builder.getCircularDependency();
Pair<FrameworkSupportInModuleProvider, FrameworkSupportInModuleProvider> pair = builder.getCircularDependency();
LOG.error("Circular dependency between types '" + pair.getFirst().getFrameworkType().getId() + "' and '" + pair.getSecond().getFrameworkType().getId() + "' was found.");
}
@@ -3,22 +3,22 @@ package com.intellij.uast;
import com.intellij.lang.Language;
import com.intellij.lang.MetaLanguage;
import gnu.trove.THashSet;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.uast.UastLanguagePlugin;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
public final class UastMetaLanguage extends MetaLanguage {
private final Set<Language> myLanguages;
protected UastMetaLanguage() {
private UastMetaLanguage() {
super("UAST");
Collection<UastLanguagePlugin> languagePlugins = UastLanguagePlugin.Companion.getInstances();
myLanguages = new THashSet<>(languagePlugins.size());
myLanguages = new HashSet<>(languagePlugins.size());
initLanguages(languagePlugins);
UastLanguagePlugin.Companion.getExtensionPointName().addChangeListener(() -> {
@@ -18,7 +18,8 @@ import com.intellij.openapi.util.Disposer;
import com.intellij.util.EventDispatcher;
import com.intellij.util.containers.ContainerUtil;
import com.intellij.util.ui.EmptyClipboardOwner;
import gnu.trove.TIntArrayList;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntCollection;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.TestOnly;
@@ -29,7 +30,7 @@ import java.awt.datatransfer.StringSelection;
import java.util.List;
import java.util.*;
public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, Disposable, Dumpable, InlayModel.Listener {
public final class CaretModelImpl implements CaretModel, PrioritizedDocumentListener, Disposable, Dumpable, InlayModel.Listener {
private final EditorImpl myEditor;
private final EventDispatcher<CaretListener> myCaretListeners = EventDispatcher.create(CaretListener.class);
@@ -428,10 +429,10 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
int index = 0;
int oldCaretCount = myCarets.size();
Iterator<CaretImpl> caretIterator = myCarets.iterator();
TIntArrayList selectionStartsBefore = null;
TIntArrayList selectionStartsAfter = null;
TIntArrayList selectionEndsBefore = null;
TIntArrayList selectionEndsAfter = null;
IntCollection selectionStartsBefore = null;
IntCollection selectionStartsAfter = null;
IntCollection selectionEndsBefore = null;
IntCollection selectionEndsAfter = null;
for (CaretState caretState : caretStates) {
CaretImpl caret;
if (index++ < oldCaretCount) {
@@ -458,10 +459,10 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
if (caretState != null && caretState.getSelectionStart() != null && caretState.getSelectionEnd() != null) {
if (selectionStartsBefore == null) {
int capacity = caretStates.size();
selectionStartsBefore = new TIntArrayList(capacity);
selectionStartsAfter = new TIntArrayList(capacity);
selectionEndsBefore = new TIntArrayList(capacity);
selectionEndsAfter = new TIntArrayList(capacity);
selectionStartsBefore = new IntArrayList(capacity);
selectionStartsAfter = new IntArrayList(capacity);
selectionEndsBefore = new IntArrayList(capacity);
selectionEndsAfter = new IntArrayList(capacity);
}
selectionStartsBefore.add(caret.getSelectionStart());
selectionEndsBefore.add(caret.getSelectionEnd());
@@ -488,8 +489,8 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
updateSystemSelection();
}
if (selectionStartsBefore != null) {
SelectionEvent event = new SelectionEvent(myEditor, selectionStartsBefore.toNativeArray(), selectionEndsBefore.toNativeArray(),
selectionStartsAfter.toNativeArray(), selectionEndsAfter.toNativeArray());
SelectionEvent event = new SelectionEvent(myEditor, selectionStartsBefore.toIntArray(), selectionEndsBefore.toIntArray(),
selectionStartsAfter.toIntArray(), selectionEndsAfter.toIntArray());
myEditor.getSelectionModel().fireSelectionChanged(event);
}
});
@@ -582,7 +583,7 @@ public class CaretModelImpl implements CaretModel, PrioritizedDocumentListener,
if (placement == Inlay.Placement.INLINE) {
doWithCaretMerging(() -> {
for (CaretImpl caret : myCarets) {
caret.onInlayRemoved(inlay.getOffset(), ((InlineInlayImpl)inlay).getOrder());
caret.onInlayRemoved(inlay.getOffset(), ((InlineInlayImpl<?>)inlay).getOrder());
}
});
}
@@ -33,6 +33,7 @@ import com.intellij.util.io.storage.*;
import gnu.trove.TIntArrayList;
import gnu.trove.TObjectHashingStrategy;
import it.unimi.dsi.fastutil.ints.IntArrayList;
import it.unimi.dsi.fastutil.ints.IntList;
import org.jetbrains.annotations.*;
import javax.swing.*;
@@ -181,7 +182,7 @@ public final class FSRecords {
private static ContentHashEnumerator myContentHashesEnumerator;
private static File myRootsFile;
private static final VfsDependentEnum<String> myAttributesList = new VfsDependentEnum<>("attrib", EnumeratorStringDescriptor.INSTANCE, 1);
private static final TIntArrayList myFreeRecords = new TIntArrayList();
private static final IntList myFreeRecords = new IntArrayList();
private static volatile boolean myDirty;
/** accessed under {@link #r}/{@link #w} */
@@ -214,7 +215,7 @@ public final class FSRecords {
}
static int getFreeRecord() {
return myFreeRecords.isEmpty() ? 0 : myFreeRecords.remove(myFreeRecords.size() - 1);
return myFreeRecords.isEmpty() ? 0 : myFreeRecords.removeInt(myFreeRecords.size() - 1);
}
private static void createBrokenMarkerFile(@Nullable Throwable reason) {
@@ -1116,7 +1117,7 @@ public final class FSRecords {
int nameId = dup.getNameId();
assert nameId > 0 : existingList;
ChildInfoImpl replaced = new ChildInfoImpl(oldChild.getId(), nameId, dup.getFileAttributes(), dup.getChildren(),
dup.getSymLinkTarget());
dup.getSymLinkTarget());
result.set(dupI, replaced);
}
j++;
@@ -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.debugger
import org.jetbrains.concurrency.Promise
@@ -22,7 +22,7 @@ interface SuspendContext<out CALL_FRAME : CallFrame> {
var methodReturnValue: Variable?
get() = null
set(v) {}
set(_) {}
/**
* Call frames for the current suspended state (from the innermost (top) frame to the main (bottom) frame)
@@ -1,9 +1,9 @@
// 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.debugger.sourcemap
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.Url
import gnu.trove.THashMap
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap
class NestedSourceMap(private val childMap: SourceMap, private val parentMap: SourceMap) : SourceMap {
override val sourceResolver: SourceResolver
@@ -14,7 +14,7 @@ class NestedSourceMap(private val childMap: SourceMap, private val parentMap: So
private val sourceIndexToSourceMappings = arrayOfNulls<Mappings>(parentMap.sources.size)
private val childMappingToTransformed = THashMap<MappingEntry, MappingEntry>()
private val childMappingToTransformed = Object2ObjectOpenHashMap<MappingEntry, MappingEntry>()
override val outFile: String?
get() = childMap.outFile
@@ -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.debugger.sourcemap
import com.intellij.openapi.util.SystemInfo
@@ -8,8 +8,11 @@ import com.intellij.openapi.vfs.VfsUtilCore
import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.Url
import com.intellij.util.Urls
import com.intellij.util.containers.ObjectIntHashMap
import com.intellij.util.io.URLUtil
import it.unimi.dsi.fastutil.Hash
import it.unimi.dsi.fastutil.objects.Object2IntMap
import it.unimi.dsi.fastutil.objects.Object2IntOpenCustomHashMap
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap
import org.jetbrains.debugger.ScriptDebuggerUrls
import java.io.File
@@ -17,7 +20,7 @@ interface SourceFileResolver {
/**
* Return -1 if no match
*/
fun resolve(map: ObjectIntHashMap<Url>): Int = -1
fun resolve(map: Object2IntMap<Url>): Int = -1
fun resolve(rawSources: List<String>): Int = -1
}
@@ -33,15 +36,19 @@ class SourceResolver(private val rawSources: List<String>,
Array(rawSources.size) { canonicalizeUrl(rawSources[it], baseUrl, trimFileScheme, baseUrlIsFile) }
}
private val canonicalizedUrlToSourceIndex: ObjectIntHashMap<Url> by lazy {
(
if (SystemInfo.isFileSystemCaseSensitive) ObjectIntHashMap(rawSources.size)
else ObjectIntHashMap(rawSources.size, Urls.caseInsensitiveUrlHashingStrategy)
).also {
for (i in rawSources.indices) {
it.put(canonicalizedUrls[i], i)
}
private val canonicalizedUrlToSourceIndex: Object2IntMap<Url> by lazy {
val map: Object2IntMap<Url> = if (SystemInfo.isFileSystemCaseSensitive) {
Object2IntOpenHashMap(rawSources.size)
}
else {
Object2IntOpenCustomHashMap(rawSources.size, CaseInsensitiveUrlHashingStrategy)
}
map.defaultReturnValue(-1)
for (i in rawSources.indices) {
map.put(canonicalizedUrls[i], i)
}
map
}
fun getSource(entry: MappingEntry): Url? {
@@ -49,7 +56,7 @@ class SourceResolver(private val rawSources: List<String>,
return if (index < 0) null else canonicalizedUrls[index]
}
fun getSourceIndex(url: Url): Int = canonicalizedUrlToSourceIndex[url]
fun getSourceIndex(url: Url): Int = canonicalizedUrlToSourceIndex.getInt(url)
internal fun findSourceIndex(resolver: SourceFileResolver): Int {
val resolveByCanonicalizedUrls = resolver.resolve(canonicalizedUrlToSourceIndex)
@@ -57,7 +64,7 @@ class SourceResolver(private val rawSources: List<String>,
}
fun findSourceIndex(sourceUrl: Url, sourceFile: VirtualFile?, localFileUrlOnly: Boolean): Int {
val index = canonicalizedUrlToSourceIndex.get(sourceUrl)
val index = canonicalizedUrlToSourceIndex.getInt(sourceUrl)
if (index != -1) {
return index
}
@@ -70,7 +77,7 @@ class SourceResolver(private val rawSources: List<String>,
internal fun findSourceIndexByFile(sourceFile: VirtualFile, localFileUrlOnly: Boolean): Int {
if (!localFileUrlOnly) {
val index = canonicalizedUrlToSourceIndex.get(Urls.newFromVirtualFile(sourceFile).trimParameters())
val index = canonicalizedUrlToSourceIndex.getInt(Urls.newFromVirtualFile(sourceFile).trimParameters())
if (index != -1) {
return index
}
@@ -80,7 +87,7 @@ class SourceResolver(private val rawSources: List<String>,
return -1
}
val index = canonicalizedUrlToSourceIndex.get(ScriptDebuggerUrls.newLocalFileUrl(sourceFile))
val index = canonicalizedUrlToSourceIndex.getInt(ScriptDebuggerUrls.newLocalFileUrl(sourceFile))
if (index != -1) {
return index
}
@@ -160,3 +167,9 @@ fun doCanonicalize(url: String, baseUrl: Url, baseUrlIsFile: Boolean, asLocalFil
return Urls.newUrl(baseUrl.scheme, baseUrl.authority, split[0], if (split.size > 1) '?' + split[1] else null)
}
}
private object CaseInsensitiveUrlHashingStrategy: Hash.Strategy<Url> {
override fun hashCode(url: Url?) = url?.hashCodeCaseInsensitive() ?: 0
override fun equals(url1: Url, url2: Url) = Urls.equals(url1, url2, caseSensitive = false, ignoreParameters = false)
}
@@ -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.containers;
import com.intellij.util.ArrayUtilRt;
@@ -9,9 +9,9 @@ import gnu.trove.TIntProcedure;
import java.util.NoSuchElementException;
public class EmptyIntHashSet extends TIntHashSet {
public final class EmptyIntHashSet extends TIntHashSet {
public static final TIntHashSet INSTANCE = new EmptyIntHashSet();
public static final TIntIterator EMPTY_INT_ITERATOR = new TIntIterator(INSTANCE) {
private static final TIntIterator EMPTY_INT_ITERATOR = new TIntIterator(INSTANCE) {
@Override
public int next() {
throw new NoSuchElementException();