From e855f5a4f0e0883b29cf3f3acc035dbb16e05445 Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Fri, 8 May 2020 09:17:57 +0200 Subject: [PATCH] use type-specific map to consume less memory GitOrigin-RevId: 1a592c99f697dc0910f58d0276a525e14d6cbcda --- .idea/libraries/fastutil_min.xml | 4 +- .../impl/intellij.java.execution.impl.iml | 1 + .../indices/DiscoveredTestDataHolder.java | 10 +-- .../indices/DiscoveredTestsIndex.java | 26 ++++---- .../indices/IntArrayExternalizer.java | 12 ++-- .../testDiscovery/indices/UsedSources.java | 12 ++-- java/idea-ui/intellij.java.ui.iml | 1 + .../roots/ui/configuration/SidePanel.java | 7 +- java/java-tests/intellij.java.tests.iml | 1 + json/intellij.json.iml | 1 + .../jsonSchema/impl/MatchResult.java | 22 +++---- .../src/com/intellij/diff/util/IntPair.java | 22 ++----- .../diff/comparison/ChangeCorrector.java | 26 ++------ .../comparison/ComparisonManagerImpl.java | 27 ++------ .../com/intellij/diff/comparison/TrimUtil.kt | 41 ++++-------- .../vcs/ex/LineStatusMarkerRenderer.java | 14 ++-- .../comparison/ComparisonMergeUtilTestBase.kt | 8 +-- .../diff/comparison/ComparisonUtilTest.kt | 34 +++------- .../diff/comparison/ComparisonUtilTestBase.kt | 4 +- .../comparison/IgnoreComparisonUtilTest.kt | 4 +- .../com/intellij/diff/util/LineOffsetsTest.kt | 23 ++----- .../intellij.platform.duplicates.analysis.iml | 1 + .../dupLocator/index/DuplicatesIndex.java | 65 ++++++++++--------- .../index/DuplicatesInspectionBase.java | 46 ++++++------- .../intellij/openapi/editor/InlayModel.java | 8 +-- .../intellij.platform.execution.impl.iml | 1 + .../ui/layout/impl/RunnerLayout.java | 15 ++--- platform/lang-api/intellij.platform.lang.iml | 1 + .../AbstractCodeStylePropertyMapper.java | 10 ++- .../properties/ExternalStringAccessor.java | 3 +- .../properties/MagicIntegerConstAccessor.java | 29 +++++---- .../testframework/TestIconMapper.java | 24 ++----- .../src/com/intellij/formatting/WrapType.java | 8 +-- .../extractor/values/Generation.java | 13 ++-- .../lang-impl/intellij.platform.lang.impl.iml | 3 +- .../intellij.platform.lang.tests.iml | 1 + .../printing/ExportToHTMLManager.java | 9 +-- .../codeEditor/printing/HTMLTextPainter.java | 22 ++++--- .../hint/ParameterInfoComponent.java | 17 +++-- .../lookup/impl/LookupCellRenderer.java | 19 +++--- .../refactoring/rename/RenameUtil.java | 12 ++-- .../lvcs-impl/intellij.platform.lvcs.impl.iml | 1 + .../ui/models/SelectionCalculator.java | 28 ++------ .../platform-api/intellij.platform.ide.iml | 1 + .../intellij/ide/wizard/AbstractWizardEx.java | 21 +----- .../com/intellij/openapi/MnemonicHelper.java | 11 ++-- .../src/com/intellij/util/IntPair.java | 31 +++++++++ .../util/ui/update/MergingUpdateQueue.java | 6 +- .../intellij/ide/ui/search/SearchUtil.java | 38 ++++++----- .../src/com/intellij/idea/SocketLock.java | 19 ++++-- .../impl/FoldingAnchorsOverlayStrategy.java | 25 ++----- .../openapi/editor/impl/IndentsModelImpl.java | 43 ++---------- .../openapi/editor/impl/InlayModelImpl.java | 36 +++++----- .../editor/impl/view/EditorPainter.java | 31 ++++----- .../editor/impl/view/EditorSizeManager.java | 24 +++---- .../src/com/intellij/ui/KeyStrokeAdapter.java | 3 +- .../intellij.platform.statistics.iml | 1 + .../eventLog/ShortcutDataProvider.java | 10 ++- .../util/containers/BidirectionalMap.java | 18 +---- .../util/containers/IntArrayList.java | 6 +- platform/vcs-api/intellij.platform.vcs.iml | 1 + .../annotate/VcsRareLineAnnotationData.java | 27 ++------ .../vcs-impl/intellij.platform.vcs.impl.iml | 1 + .../impl/patch/apply/GenericPatchApplier.java | 18 ++--- .../DateChangeListGroupingStrategy.java | 34 +++++----- .../issueLinks/IssueLinkHtmlRenderer.java | 18 +---- .../impl/VcsSelectionHistoryDialog.java | 17 ++--- .../unscramble/AnnotateStackTraceAction.java | 32 +++++---- plugins/svn4idea/intellij.vcs.svn.iml | 1 + .../svn/annotate/BaseSvnFileAnnotation.java | 13 ++-- plugins/yaml/intellij.yaml.iml | 1 + .../yaml/psi/impl/YAMLQuotedTextImpl.java | 43 +++++------- xml/xml-psi-impl/intellij.xml.psi.impl.iml | 1 + .../com/intellij/xml/util/ColorIconCache.java | 13 ++-- 74 files changed, 511 insertions(+), 669 deletions(-) create mode 100644 platform/platform-api/src/com/intellij/util/IntPair.java diff --git a/.idea/libraries/fastutil_min.xml b/.idea/libraries/fastutil_min.xml index a0fbf968439e..093fc5abd6c2 100644 --- a/.idea/libraries/fastutil_min.xml +++ b/.idea/libraries/fastutil_min.xml @@ -1,8 +1,8 @@ - + - + diff --git a/java/execution/impl/intellij.java.execution.impl.iml b/java/execution/impl/intellij.java.execution.impl.iml index 33b02cfea857..8d961f350c07 100644 --- a/java/execution/impl/intellij.java.execution.impl.iml +++ b/java/execution/impl/intellij.java.execution.impl.iml @@ -30,6 +30,7 @@ + diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java index 3cd09e90bb5c..e0c383113423 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestDataHolder.java @@ -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.testDiscovery.indices; import com.intellij.openapi.Disposable; @@ -9,7 +9,8 @@ import com.intellij.openapi.util.LowMemoryWatcher; import com.intellij.util.containers.MultiMap; import com.intellij.util.indexing.StorageException; import com.intellij.util.io.*; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -182,11 +183,10 @@ public final class DiscoveredTestDataHolder { @NotNull List usedFiles, @Nullable String moduleName, byte frameworkId) throws IOException { - final int testNameId = myTestEnumerator.enumerate(createTestId(testClassName, testMethodName, frameworkId)); - Map result = new HashMap<>(); + Int2ObjectOpenHashMap result = new Int2ObjectOpenHashMap<>(); for (Map.Entry> e : usedMethods.entrySet()) { - TIntArrayList methodIds = new TIntArrayList(e.getValue().size()); + IntArrayList methodIds = new IntArrayList(e.getValue().size()); result.put(myClassEnumerator.enumerate(e.getKey()), methodIds); for (String methodName : e.getValue()) { methodIds.add(myMethodEnumerator.enumerate(methodName)); diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java index 0faae0bb3f5b..724ccf29223c 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/DiscoveredTestsIndex.java @@ -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.testDiscovery.indices; import com.intellij.openapi.progress.ProgressManager; @@ -9,16 +9,18 @@ import com.intellij.util.indexing.impl.MapIndexStorage; import com.intellij.util.indexing.impl.MapReduceIndex; import com.intellij.util.indexing.impl.forward.KeyCollectionForwardIndexAccessor; import com.intellij.util.indexing.impl.forward.PersistentMapBasedForwardIndex; -import com.intellij.util.io.*; -import gnu.trove.TIntArrayList; +import com.intellij.util.io.DataExternalizer; +import com.intellij.util.io.EnumeratorIntegerDescriptor; +import com.intellij.util.io.IntCollectionDataExternalizer; +import com.intellij.util.io.KeyDescriptor; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NotNull; -import java.io.File; import java.io.IOException; import java.nio.file.Path; -public class DiscoveredTestsIndex extends MapReduceIndex { - protected DiscoveredTestsIndex(@NotNull Path file) throws IOException { +public final class DiscoveredTestsIndex extends MapReduceIndex { + DiscoveredTestsIndex(@NotNull Path file) throws IOException { super(INDEX_EXTENSION, new MyIndexStorage(file), new PersistentMapBasedForwardIndex(file.resolve("forward.idx"), false), @@ -39,7 +41,7 @@ public class DiscoveredTestsIndex extends MapReduceIndex { + private static class MyIndexStorage extends MapIndexStorage { protected MyIndexStorage(@NotNull Path storageFile) throws IOException { super(storageFile, EnumeratorIntegerDescriptor.INSTANCE, IntArrayExternalizer.INSTANCE, 4 * 1024, false); } @@ -50,16 +52,18 @@ public class DiscoveredTestsIndex extends MapReduceIndex INDEX_EXTENSION = new IndexExtension() { + private static final IndexExtension INDEX_EXTENSION = new IndexExtension() { @NotNull @Override - public IndexId getName() { + public IndexId getName() { return IndexId.create("jvm.discovered.tests"); } @NotNull @Override - public DataIndexer getIndexer() {return inputData -> inputData.myUsedMethods;} + public DataIndexer getIndexer() { + return inputData -> inputData.myUsedMethods; + } @NotNull @Override @@ -69,7 +73,7 @@ public class DiscoveredTestsIndex extends MapReduceIndex getValueExternalizer() { + public DataExternalizer getValueExternalizer() { return IntArrayExternalizer.INSTANCE; } diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/IntArrayExternalizer.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/IntArrayExternalizer.java index 97537a812895..0b850de40b76 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/IntArrayExternalizer.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/IntArrayExternalizer.java @@ -1,20 +1,20 @@ -// 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.testDiscovery.indices; import com.intellij.util.io.DataExternalizer; import com.intellij.util.io.DataInputOutputUtil; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NotNull; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -class IntArrayExternalizer implements DataExternalizer { +final class IntArrayExternalizer implements DataExternalizer { static final IntArrayExternalizer INSTANCE = new IntArrayExternalizer(); @Override - public void save(@NotNull DataOutput out, TIntArrayList value) throws IOException { + public void save(@NotNull DataOutput out, IntArrayList value) throws IOException { DataInputOutputUtil.writeINT(out, value.size()); for (int i = 0; i < value.size(); i++) { DataInputOutputUtil.writeINT(out, value.get(i)); @@ -22,9 +22,9 @@ class IntArrayExternalizer implements DataExternalizer { } @Override - public TIntArrayList read(@NotNull DataInput in) throws IOException { + public IntArrayList read(@NotNull DataInput in) throws IOException { int size = DataInputOutputUtil.readINT(in); - TIntArrayList array = new TIntArrayList(size); + IntArrayList array = new IntArrayList(size); for (int i = 0; i < size; i++) { array.add(DataInputOutputUtil.readINT(in)); } diff --git a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/UsedSources.java b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/UsedSources.java index c3546b9d2dbc..a01119313d5c 100644 --- a/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/UsedSources.java +++ b/java/execution/impl/src/com/intellij/execution/testDiscovery/indices/UsedSources.java @@ -1,17 +1,19 @@ -// 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.testDiscovery.indices; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NotNull; import java.util.Map; -class UsedSources { +final class UsedSources { @NotNull - final Map myUsedMethods; + final Int2ObjectOpenHashMap myUsedMethods; @NotNull final Map myUsedFiles; - UsedSources(@NotNull Map methods, @NotNull Map files) { + + UsedSources(@NotNull Int2ObjectOpenHashMap methods, @NotNull Map files) { myUsedMethods = methods; myUsedFiles = files; } diff --git a/java/idea-ui/intellij.java.ui.iml b/java/idea-ui/intellij.java.ui.iml index 713509b3e97a..566c287db127 100644 --- a/java/idea-ui/intellij.java.ui.iml +++ b/java/idea-ui/intellij.java.ui.iml @@ -26,5 +26,6 @@ + \ No newline at end of file diff --git a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java index fce8a1026e1a..104f6f27f65f 100644 --- a/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java +++ b/java/idea-ui/src/com/intellij/openapi/roots/ui/configuration/SidePanel.java @@ -11,6 +11,7 @@ import com.intellij.ui.popup.list.GroupedItemsListRenderer; import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -19,15 +20,13 @@ import javax.swing.*; import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionListener; import java.awt.*; -import java.util.HashMap; -import java.util.Map; -public class SidePanel extends JPanel { +public final class SidePanel extends JPanel { private final JList myList; private final DefaultListModel myModel; private final Place.Navigator myNavigator; - private final Map myIndex2Separator = new HashMap<>(); + private final Int2ObjectOpenHashMap myIndex2Separator = new Int2ObjectOpenHashMap<>(); public SidePanel(Place.Navigator navigator) { myNavigator = navigator; diff --git a/java/java-tests/intellij.java.tests.iml b/java/java-tests/intellij.java.tests.iml index f88c8e9f1534..07f57f023c01 100644 --- a/java/java-tests/intellij.java.tests.iml +++ b/java/java-tests/intellij.java.tests.iml @@ -4,6 +4,7 @@ + diff --git a/json/intellij.json.iml b/json/intellij.json.iml index 1205c8749da9..c8b9e62e17db 100644 --- a/json/intellij.json.iml +++ b/json/intellij.json.iml @@ -17,5 +17,6 @@ + \ No newline at end of file diff --git a/json/src/com/jetbrains/jsonSchema/impl/MatchResult.java b/json/src/com/jetbrains/jsonSchema/impl/MatchResult.java index 6bcca9dd3255..5d42473ae7f8 100644 --- a/json/src/com/jetbrains/jsonSchema/impl/MatchResult.java +++ b/json/src/com/jetbrains/jsonSchema/impl/MatchResult.java @@ -1,9 +1,8 @@ -// 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.jetbrains.jsonSchema.impl; import com.intellij.util.Processor; -import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.MultiMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -11,7 +10,7 @@ import java.util.*; /** * @author Irina.Chernushina on 4/22/2017. */ -public class MatchResult { +public final class MatchResult { public final List mySchemas; public final List> myExcludingSchemas; @@ -22,7 +21,7 @@ public class MatchResult { public static MatchResult create(@NotNull JsonSchemaTreeNode root) { List schemas = new ArrayList<>(); - MultiMap oneOfGroups = MultiMap.create(); + Int2ObjectOpenHashMap> oneOfGroups = new Int2ObjectOpenHashMap<>(); iterateTree(root, node -> { if (node.isAny()) return true; int groupNumber = node.getExcludingGroupNumber(); @@ -30,15 +29,16 @@ public class MatchResult { schemas.add(node.getSchema()); } else { - oneOfGroups.putValue(groupNumber, node.getSchema()); + oneOfGroups.computeIfAbsent(groupNumber, __ -> new ArrayList<>()).add(node.getSchema()); } return true; }); - List> result = oneOfGroups.isEmpty() - ? ContainerUtil.emptyList() - : new ArrayList<>(oneOfGroups.keySet().size()); - for (Map.Entry> entry: oneOfGroups.entrySet()) { - result.add(entry.getValue()); + List> result; + if (oneOfGroups.isEmpty()) { + result = Collections.emptyList(); + } + else { + result = new ArrayList<>(oneOfGroups.values()); } return new MatchResult(schemas, result); } diff --git a/platform/diff-api/src/com/intellij/diff/util/IntPair.java b/platform/diff-api/src/com/intellij/diff/util/IntPair.java index efbb84b175e6..67d08bcda501 100644 --- a/platform/diff-api/src/com/intellij/diff/util/IntPair.java +++ b/platform/diff-api/src/com/intellij/diff/util/IntPair.java @@ -1,21 +1,11 @@ -/* - * 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.diff.util; -public class IntPair { +/** + * @deprecated Use {@link com.intellij.util.IntPair} + */ +@Deprecated +public final class IntPair { public final int val1; public final int val2; diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/ChangeCorrector.java b/platform/diff-impl/src/com/intellij/diff/comparison/ChangeCorrector.java index 607daeb00314..8a67f49e9eb1 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/ChangeCorrector.java +++ b/platform/diff-impl/src/com/intellij/diff/comparison/ChangeCorrector.java @@ -1,26 +1,12 @@ -/* - * 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.diff.comparison; import com.intellij.diff.comparison.ByLine.Line; import com.intellij.diff.comparison.iterables.DiffIterableUtil; import com.intellij.diff.comparison.iterables.FairDiffIterable; -import com.intellij.diff.util.IntPair; import com.intellij.diff.util.Range; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.util.IntPair; import gnu.trove.TIntArrayList; import org.jetbrains.annotations.NotNull; @@ -71,10 +57,10 @@ abstract class ChangeCorrector { IntPair range1 = getOriginalRange1(ch.start1 + i); IntPair range2 = getOriginalRange2(ch.start2 + i); - int start1 = range1.val1; - int start2 = range2.val1; - int end1 = range1.val2; - int end2 = range2.val2; + int start1 = range1.first; + int start2 = range2.first; + int end1 = range1.second; + int end2 = range2.second; matchGap(last1, start1, last2, start2); myBuilder.markEqual(start1, start2, end1, end2); diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/ComparisonManagerImpl.java b/platform/diff-impl/src/com/intellij/diff/comparison/ComparisonManagerImpl.java index b0d2c75e15b0..c87001c4ff81 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/ComparisonManagerImpl.java +++ b/platform/diff-impl/src/com/intellij/diff/comparison/ComparisonManagerImpl.java @@ -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 com.intellij.diff.comparison; import com.intellij.diff.comparison.iterables.DiffIterable; @@ -21,14 +7,13 @@ import com.intellij.diff.comparison.iterables.FairDiffIterable; import com.intellij.diff.fragments.*; import com.intellij.diff.tools.util.text.LineOffsets; import com.intellij.diff.tools.util.text.LineOffsetsUtil; -import com.intellij.diff.util.IntPair; import com.intellij.diff.util.MergeRange; import com.intellij.diff.util.Range; -import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.util.Consumer; +import com.intellij.util.IntPair; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.diff.FilesTooBigForDiffException; import com.intellij.util.text.CharSequenceSubSequence; @@ -43,9 +28,7 @@ import java.util.List; import static com.intellij.diff.comparison.iterables.DiffIterableUtil.fair; import static java.util.Collections.singletonList; -public class ComparisonManagerImpl extends ComparisonManager { - private static final Logger LOG = Logger.getInstance(ComparisonManagerImpl.class); - +public final class ComparisonManagerImpl extends ComparisonManager { @NotNull public static ComparisonManagerImpl getInstanceImpl() { return (ComparisonManagerImpl)getInstance(); @@ -369,7 +352,7 @@ public class ComparisonManagerImpl extends ComparisonManager { IntPair offsets2 = getOffsets(lineOffsets2, startLine2, endLine2); fragments.add(new LineFragmentImpl(startLine1, endLine1, startLine2, endLine2, - offsets1.val1, offsets1.val2, offsets2.val1, offsets2.val2)); + offsets1.first, offsets1.second, offsets2.first, offsets2.second)); } return fragments; } @@ -763,7 +746,7 @@ public class ComparisonManagerImpl extends ComparisonManager { @NotNull private static TextRange trimIgnoredRange(int start, int end, @NotNull BitSet ignored, int offset) { IntPair intPair = TrimUtil.trim(offset + start, offset + end, ignored); - return new TextRange(intPair.val1 - offset, intPair.val2 - offset); + return new TextRange(intPair.first - offset, intPair.second - offset); } private static boolean isIgnoredRange(@NotNull BitSet ignored, int start, int end) { diff --git a/platform/diff-impl/src/com/intellij/diff/comparison/TrimUtil.kt b/platform/diff-impl/src/com/intellij/diff/comparison/TrimUtil.kt index a9e895af8992..9fd3ee2c657b 100644 --- a/platform/diff-impl/src/com/intellij/diff/comparison/TrimUtil.kt +++ b/platform/diff-impl/src/com/intellij/diff/comparison/TrimUtil.kt @@ -1,24 +1,9 @@ -/* - * 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. @file:JvmName("TrimUtil") @file:Suppress("NAME_SHADOWING") package com.intellij.diff.comparison -import com.intellij.diff.util.IntPair import com.intellij.diff.util.MergeRange import com.intellij.diff.util.Range import com.intellij.openapi.util.text.StringUtil.isWhiteSpace @@ -60,12 +45,12 @@ fun isContinuousScript(c: Int): Boolean { script == Character.UnicodeScript.JAVANESE } -fun trim(text: CharSequence, start: Int, end: Int): IntPair { +fun trim(text: CharSequence, start: Int, end: Int): com.intellij.util.IntPair { return trim(start, end, { index -> isWhiteSpace(text[index]) }) } -fun trim(start: Int, end: Int, ignored: BitSet): IntPair { +fun trim(start: Int, end: Int, ignored: BitSet): com.intellij.util.IntPair { return trim(start, end, { index -> ignored[index] }) } @@ -313,14 +298,14 @@ private inline fun trim(start1: Int, start2: Int, start3: Int, end1: Int, end2: } private inline fun trim(start: Int, end: Int, - ignored: (Int) -> Boolean): IntPair { + ignored: (Int) -> Boolean): com.intellij.util.IntPair { var start = start var end = end start = trimStart(start, end, ignored) end = trimEnd(start, end, ignored) - return IntPair(start, end) + return com.intellij.util.IntPair(start, end) } private inline fun trimStart(start: Int, end: Int, @@ -534,12 +519,12 @@ private inline fun trimExpand(start1: Int, start2: Int, end1: Int, end2: Int, var end2 = end2 val starts = trimExpandForward(start1, start2, end1, end2, equals, ignored1, ignored2) - start1 = starts.val1 - start2 = starts.val2 + start1 = starts.first + start2 = starts.second val ends = trimExpandBackward(start1, start2, end1, end2, equals, ignored1, ignored2) - end1 = ends.val1 - end2 = ends.val2 + end1 = ends.first + end2 = ends.second return Range(start1, end1, start2, end2) } @@ -547,7 +532,7 @@ private inline fun trimExpand(start1: Int, start2: Int, end1: Int, end2: Int, private inline fun trimExpandForward(start1: Int, start2: Int, end1: Int, end2: Int, equals: (Int, Int) -> Boolean, ignored1: (Int) -> Boolean, - ignored2: (Int) -> Boolean): IntPair { + ignored2: (Int) -> Boolean): com.intellij.util.IntPair { var start1 = start1 var start2 = start2 @@ -573,13 +558,13 @@ private inline fun trimExpandForward(start1: Int, start2: Int, end1: Int, end2: start1 = trimStart(start1, end1, ignored1) start2 = trimStart(start2, end2, ignored2) - return IntPair(start1, start2) + return com.intellij.util.IntPair(start1, start2) } private inline fun trimExpandBackward(start1: Int, start2: Int, end1: Int, end2: Int, equals: (Int, Int) -> Boolean, ignored1: (Int) -> Boolean, - ignored2: (Int) -> Boolean): IntPair { + ignored2: (Int) -> Boolean): com.intellij.util.IntPair { var end1 = end1 var end2 = end2 @@ -605,5 +590,5 @@ private inline fun trimExpandBackward(start1: Int, start2: Int, end1: Int, end2: end1 = trimEnd(start1, end1, ignored1) end2 = trimEnd(start2, end2, ignored2) - return IntPair(end1, end2) + return com.intellij.util.IntPair(end1, end2) } diff --git a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java index cf65d05087c1..1bd2d3aee909 100644 --- a/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java +++ b/platform/diff-impl/src/com/intellij/openapi/vcs/ex/LineStatusMarkerRenderer.java @@ -1,9 +1,8 @@ -// 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.vcs.ex; import com.intellij.diff.util.DiffDrawUtil; import com.intellij.diff.util.DiffUtil; -import com.intellij.diff.util.IntPair; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.DiffBundle; import com.intellij.openapi.diff.DiffColors; @@ -21,6 +20,7 @@ import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.TextRange; import com.intellij.ui.paint.LinePainter2D; import com.intellij.ui.scale.JBUIScale; +import com.intellij.util.IntPair; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.Update; @@ -273,7 +273,7 @@ public abstract class LineStatusMarkerRenderer { IntPair area = getGutterArea(editor); int y = editor.visualLineToY(startLine); int endY = editor.visualLineToY(endLine); - return new Rectangle(area.val1, y, area.val2 - area.val1, endY - y); + return new Rectangle(area.first, y, area.second - area.first, endY - y); } protected boolean shouldPaintGutter() { @@ -309,8 +309,8 @@ public abstract class LineStatusMarkerRenderer { int line2 = block.get(block.size() - 1).line2; IntPair area = getGutterArea(editor); - final int x = area.val1; - final int endX = area.val2; + final int x = area.first; + final int endX = area.second; final int y = editorImpl.visualLineToY(line1); final int endY = editorImpl.visualLineToY(line2); @@ -389,8 +389,8 @@ public abstract class LineStatusMarkerRenderer { public static void paintSimpleRange(Graphics g, Editor editor, int line1, int line2, @Nullable Color color) { IntPair horizontalArea = getGutterArea(editor); - int x = horizontalArea.val1; - int endX = horizontalArea.val2; + int x = horizontalArea.first; + int endX = horizontalArea.second; int y = lineToY(editor, line1); int endY = lineToY(editor, line2); diff --git a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt index 1d62188b8c11..c39ddac0b17b 100644 --- a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt +++ b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonMergeUtilTestBase.kt @@ -1,14 +1,14 @@ -// 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.diff.comparison import com.intellij.diff.DiffTestCase import com.intellij.diff.fragments.MergeLineFragment -import com.intellij.diff.util.IntPair import com.intellij.diff.util.MergeRange import com.intellij.diff.util.ThreeSide import com.intellij.openapi.editor.Document import com.intellij.openapi.editor.impl.DocumentImpl import com.intellij.openapi.util.Couple +import com.intellij.util.IntPair import java.util.* abstract class ComparisonMergeUtilTestBase : DiffTestCase() { @@ -215,8 +215,8 @@ abstract class ComparisonMergeUtilTestBase : DiffTestCase() { val starts = Trio(start1, start2, start3) val ends = Trio(end1, end2, end3) - fun start(side: ThreeSide): Int = this(side).val1 - fun end(side: ThreeSide): Int = this(side).val2 + fun start(side: ThreeSide): Int = this(side).first + fun end(side: ThreeSide): Int = this(side).second override fun toString(): String { return "($start1, $end1) - ($start2, $end2) - ($start3, $end3)" diff --git a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTest.kt b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTest.kt index 4750a6bbb611..7509b7016e3b 100644 --- a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTest.kt +++ b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTest.kt @@ -1,22 +1,8 @@ -/* - * 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.diff.comparison import com.intellij.diff.DiffTestCase -import com.intellij.diff.util.IntPair +import com.intellij.util.IntPair class ComparisonUtilTest : DiffTestCase() { fun testTrimEquals() { @@ -133,14 +119,14 @@ class ComparisonUtilTest : DiffTestCase() { assertTrue(fragments.size == 1, "Side: ${fragments.size})") val fragment = fragments[0] - assertEquals(offsets1.val1, fragment.startOffset1, fragment.toString()) - assertEquals(offsets1.val2, fragment.endOffset1, fragment.toString()) - assertEquals(offsets2.val1, fragment.startOffset2, fragment.toString()) - assertEquals(offsets2.val2, fragment.endOffset2, fragment.toString()) - assertEquals(lines1.val1, fragment.startLine1, fragment.toString()) - assertEquals(lines1.val2, fragment.endLine1, fragment.toString()) - assertEquals(lines2.val1, fragment.startLine2, fragment.toString()) - assertEquals(lines2.val2, fragment.endLine2, fragment.toString()) + assertEquals(offsets1.first, fragment.startOffset1, fragment.toString()) + assertEquals(offsets1.second, fragment.endOffset1, fragment.toString()) + assertEquals(offsets2.first, fragment.startOffset2, fragment.toString()) + assertEquals(offsets2.second, fragment.endOffset2, fragment.toString()) + assertEquals(lines1.first, fragment.startLine1, fragment.toString()) + assertEquals(lines1.second, fragment.endLine1, fragment.toString()) + assertEquals(lines2.first, fragment.startLine2, fragment.toString()) + assertEquals(lines2.second, fragment.endLine2, fragment.toString()) } private fun doTestTrim(expected: Boolean, string1: String, string2: String) { diff --git a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTestBase.kt b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTestBase.kt index 1c645094d137..cc68ef5842e3 100644 --- a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTestBase.kt +++ b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/ComparisonUtilTestBase.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 com.intellij.diff.comparison import com.intellij.diff.DiffTestCase import com.intellij.diff.fragments.DiffFragment import com.intellij.diff.fragments.LineFragment import com.intellij.diff.fragments.MergeWordFragment -import com.intellij.diff.util.IntPair import com.intellij.diff.util.ThreeSide import com.intellij.openapi.editor.Document import com.intellij.openapi.editor.impl.DocumentImpl import com.intellij.openapi.util.Couple +import com.intellij.util.IntPair import java.util.* abstract class ComparisonUtilTestBase : DiffTestCase() { diff --git a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/IgnoreComparisonUtilTest.kt b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/IgnoreComparisonUtilTest.kt index f7db25df5ddd..c2e3356cf00e 100644 --- a/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/IgnoreComparisonUtilTest.kt +++ b/platform/diff-impl/tests/testSrc/com/intellij/diff/comparison/IgnoreComparisonUtilTest.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.diff.comparison import com.intellij.diff.DiffTestCase @@ -8,10 +8,10 @@ import com.intellij.diff.comparison.ComparisonUtilTestBase.Companion.ins import com.intellij.diff.comparison.ComparisonUtilTestBase.Companion.mod import com.intellij.diff.fragments.LineFragment import com.intellij.diff.tools.util.text.LineOffsetsUtil -import com.intellij.diff.util.IntPair import com.intellij.diff.util.Range import com.intellij.openapi.util.Couple import com.intellij.openapi.util.TextRange +import com.intellij.util.IntPair import java.util.* class IgnoreComparisonUtilTest : DiffTestCase() { diff --git a/platform/diff-impl/tests/testSrc/com/intellij/diff/util/LineOffsetsTest.kt b/platform/diff-impl/tests/testSrc/com/intellij/diff/util/LineOffsetsTest.kt index 44eca6e4c223..2057fb22821c 100644 --- a/platform/diff-impl/tests/testSrc/com/intellij/diff/util/LineOffsetsTest.kt +++ b/platform/diff-impl/tests/testSrc/com/intellij/diff/util/LineOffsetsTest.kt @@ -1,23 +1,10 @@ -/* - * Copyright 2000-2017 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.diff.util import com.intellij.diff.DiffTestCase import com.intellij.diff.tools.util.text.LineOffsetsUtil import com.intellij.openapi.editor.impl.DocumentImpl +import com.intellij.util.IntPair class LineOffsetsTest : DiffTestCase() { fun testWithDocument() { @@ -64,8 +51,8 @@ class LineOffsetsTest : DiffTestCase() { assertEquals(offsets.size, lineOffsets.lineCount) offsets.forEachIndexed { line, value -> - assertEquals(lineOffsets.getLineStart(line), value.val1) - assertEquals(lineOffsets.getLineEnd(line), value.val2) + assertEquals(lineOffsets.getLineStart(line), value.first) + assertEquals(lineOffsets.getLineEnd(line), value.second) for (offset in lineOffsets.getLineStart(line)..lineOffsets.getLineEnd(line)) { assertEquals(line, lineOffsets.getLineNumber(offset)) @@ -74,6 +61,6 @@ class LineOffsetsTest : DiffTestCase() { } private operator fun Int.not(): IntPairHelper = IntPairHelper(this) - private operator fun IntPairHelper.minus(col: Int): IntPair = IntPair(this.line, col) + private operator fun IntPairHelper.minus(col: Int) = IntPair(this.line, col) private class IntPairHelper(val line: Int) } \ No newline at end of file diff --git a/platform/duplicates-analysis/intellij.platform.duplicates.analysis.iml b/platform/duplicates-analysis/intellij.platform.duplicates.analysis.iml index e87ff43eb430..b61d10ea4bc1 100644 --- a/platform/duplicates-analysis/intellij.platform.duplicates.analysis.iml +++ b/platform/duplicates-analysis/intellij.platform.duplicates.analysis.iml @@ -15,5 +15,6 @@ + \ No newline at end of file diff --git a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesIndex.java b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesIndex.java index 5cdbfd967f3b..2747a6d7b4db 100644 --- a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesIndex.java +++ b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesIndex.java @@ -32,8 +32,10 @@ import com.intellij.util.io.DataExternalizer; import com.intellij.util.io.DataInputOutputUtil; import com.intellij.util.io.EnumeratorIntegerDescriptor; import com.intellij.util.io.KeyDescriptor; -import gnu.trove.THashMap; -import gnu.trove.TIntArrayList; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -42,19 +44,17 @@ import org.jetbrains.annotations.TestOnly; import java.io.DataInput; import java.io.DataOutput; import java.io.IOException; -import java.util.Collections; -import java.util.Map; /** * @author Maxim.Mossienko on 12/11/13. */ -public class DuplicatesIndex extends FileBasedIndexExtension { +public class DuplicatesIndex extends FileBasedIndexExtension { static boolean ourEnabled = SystemProperties.getBooleanProperty("idea.enable.duplicates.online.calculation", true); static final boolean ourEnabledLightProfiles = true; private static boolean ourEnabledOldProfiles = false; - @NonNls public static final ID NAME = ID.create("DuplicatesIndex"); + @NonNls public static final ID NAME = ID.create("DuplicatesIndex"); private static final int myBaseVersion = 25; private final FileBasedIndex.InputFilter myInputFilter = file -> { @@ -70,36 +70,36 @@ public class DuplicatesIndex extends FileBasedIndexExtension myValueExternalizer = new DataExternalizer() { + private final DataExternalizer myValueExternalizer = new DataExternalizer() { @Override - public void save(@NotNull DataOutput out, TIntArrayList list) throws IOException { + public void save(@NotNull DataOutput out, IntArrayList list) throws IOException { if (list.size() == 2) { - DataInputOutputUtil.writeINT(out, list.getQuick(0)); - DataInputOutputUtil.writeINT(out, list.getQuick(1)); + DataInputOutputUtil.writeINT(out, list.getInt(0)); + DataInputOutputUtil.writeINT(out, list.getInt(1)); } else { DataInputOutputUtil.writeINT(out, -list.size()); int prev = 0; for (int i = 0, len = list.size(); i < len; i+=2) { - int value = list.getQuick(i); + int value = list.getInt(i); DataInputOutputUtil.writeINT(out, value - prev); prev = value; - DataInputOutputUtil.writeINT(out, list.getQuick(i + 1)); + DataInputOutputUtil.writeINT(out, list.getInt(i + 1)); } } } @Override - public TIntArrayList read(@NotNull DataInput in) throws IOException { + public IntArrayList read(@NotNull DataInput in) throws IOException { int capacityOrValue = DataInputOutputUtil.readINT(in); if (capacityOrValue >= 0) { - TIntArrayList list = new TIntArrayList(2); + IntArrayList list = new IntArrayList(2); list.add(capacityOrValue); list.add(DataInputOutputUtil.readINT(in)); return list; } capacityOrValue = -capacityOrValue; - TIntArrayList list = new TIntArrayList(capacityOrValue); + IntArrayList list = new IntArrayList(capacityOrValue); int prev = 0; while(capacityOrValue > 0) { int value = DataInputOutputUtil.readINT(in) + prev; @@ -112,28 +112,30 @@ public class DuplicatesIndex extends FileBasedIndexExtension myIndexer = new DataIndexer() { + private final DataIndexer myIndexer = new DataIndexer() { @Override @NotNull - public Map map(@NotNull final FileContent inputData) { + public Int2ObjectMap map(@NotNull final FileContent inputData) { FileType type = inputData.getFileType(); DuplicatesProfile profile = findDuplicatesProfile(type); - if (profile == null || !profile.acceptsContentForIndexing(inputData)) return Collections.emptyMap(); + if (profile == null || !profile.acceptsContentForIndexing(inputData)) { + return Int2ObjectMaps.emptyMap(); + } try { PsiDependentFileContent fileContent = (PsiDependentFileContent)inputData; if (profile instanceof LightDuplicateProfile && ourEnabledLightProfiles) { - final THashMap result = new THashMap<>(); + final Int2ObjectOpenHashMap result = new Int2ObjectOpenHashMap<>(); LighterAST ast = fileContent.getLighterAST(); ((LightDuplicateProfile)profile).process(ast, new LightDuplicateProfile.Callback() { @Override public void process(int hash, int hash2, @NotNull LighterAST ast, LighterASTNode @NotNull ... nodes) { - TIntArrayList list = result.get(hash); + IntArrayList list = result.get(hash); if (list == null) { - result.put(hash, list = new TIntArrayList(2)); + result.put(hash, list = new IntArrayList(2)); } list.add(nodes[0].getStartOffset()); list.add(hash2); @@ -147,8 +149,9 @@ public class DuplicatesIndex extends FileBasedIndexExtension getName() { + public ID getName() { return NAME; } @NotNull @Override - public DataIndexer getIndexer() { + public DataIndexer getIndexer() { return myIndexer; } @NotNull @Override - public DataExternalizer getValueExternalizer() { + public DataExternalizer getValueExternalizer() { return myValueExternalizer; } @@ -206,8 +209,8 @@ public class DuplicatesIndex extends FileBasedIndexExtension myMap = new THashMap<>(); + private static final class MyFragmentsCollector implements FragmentsCollector { + private final Int2ObjectOpenHashMap myMap = new Int2ObjectOpenHashMap<>(); private final DuplicatesProfile myProfile; private final DuplocatorState myDuplocatorState; @@ -224,13 +227,13 @@ public class DuplicatesIndex extends FileBasedIndexExtension getMap() { + public Int2ObjectOpenHashMap getMap() { return myMap; } } diff --git a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java index 81734db97b87..7771425a76a7 100644 --- a/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java +++ b/platform/duplicates-analysis/src/com/intellij/dupLocator/index/DuplicatesInspectionBase.java @@ -40,18 +40,10 @@ import com.intellij.psi.search.GlobalSearchScope; import com.intellij.psi.tree.ILightStubFileElementType; import com.intellij.util.SmartList; import com.intellij.util.indexing.FileBasedIndex; -import gnu.trove.TIntArrayList; -import gnu.trove.TIntIntHashMap; -import gnu.trove.TIntLongHashMap; -import gnu.trove.TIntObjectHashMap; +import it.unimi.dsi.fastutil.ints.*; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import java.util.Iterator; -import java.util.Map; -import java.util.SortedMap; -import java.util.TreeMap; - public class DuplicatesInspectionBase extends LocalInspectionTool { public boolean myFilterOutGeneratedCode; private static final int MIN_FRAGMENT_SIZE = 3; // todo 3 statements constant @@ -80,8 +72,8 @@ public class DuplicatesInspectionBase extends LocalInspectionTool { final SmartList descriptors = new SmartList<>(); final VirtualFile baseDir = project.getBaseDir(); - for (Map.Entry entry : processor.reportedRanges.entrySet()) { - final Integer offset = entry.getKey(); + for (Int2ObjectMap.Entry entry : processor.reportedRanges.int2ObjectEntrySet()) { + int offset = entry.getIntKey(); if (!usingLightProfile && processor.fragmentSize.get(offset) < MIN_FRAGMENT_SIZE) continue; final VirtualFile file = processor.reportedFiles.get(offset); String path = null; @@ -178,7 +170,7 @@ public class DuplicatesInspectionBase extends LocalInspectionTool { return null; } - private class LightDuplicatedCodeProcessor extends DuplicatedCodeProcessor { + private final class LightDuplicatedCodeProcessor extends DuplicatedCodeProcessor { private final TreeBackedLighterAST myAst; private LightDuplicatedCodeProcessor(@NotNull TreeBackedLighterAST ast, VirtualFile file, Project project) { @@ -212,7 +204,7 @@ public class DuplicatesInspectionBase extends LocalInspectionTool { } } - class OldDuplicatedCodeProcessor extends DuplicatedCodeProcessor { + final class OldDuplicatedCodeProcessor extends DuplicatedCodeProcessor { private OldDuplicatedCodeProcessor(VirtualFile file, Project project) { super(file, project, myFilterOutGeneratedCode); } @@ -255,13 +247,13 @@ public class DuplicatesInspectionBase extends LocalInspectionTool { } } - abstract static class DuplicatedCodeProcessor implements FileBasedIndex.ValueProcessor { - final TreeMap reportedRanges = new TreeMap<>(); - final TIntObjectHashMap reportedFiles = new TIntObjectHashMap<>(); - final TIntObjectHashMap reportedPsi = new TIntObjectHashMap<>(); - final TIntIntHashMap reportedOffsetInOtherFiles = new TIntIntHashMap(); - final TIntIntHashMap fragmentSize = new TIntIntHashMap(); - final TIntLongHashMap fragmentHash = new TIntLongHashMap(); + abstract static class DuplicatedCodeProcessor implements FileBasedIndex.ValueProcessor { + final Int2ObjectRBTreeMap reportedRanges = new Int2ObjectRBTreeMap<>(); + final Int2ObjectOpenHashMap reportedFiles = new Int2ObjectOpenHashMap<>(); + final Int2ObjectOpenHashMap reportedPsi = new Int2ObjectOpenHashMap<>(); + final Int2IntOpenHashMap reportedOffsetInOtherFiles = new Int2IntOpenHashMap(); + final Int2IntOpenHashMap fragmentSize = new Int2IntOpenHashMap(); + final Int2LongOpenHashMap fragmentHash = new Int2LongOpenHashMap(); final VirtualFile virtualFile; final Project project; final FileIndex myFileIndex; @@ -288,12 +280,12 @@ public class DuplicatesInspectionBase extends LocalInspectionTool { } @Override - public boolean process(@NotNull VirtualFile file, TIntArrayList list) { + public boolean process(@NotNull VirtualFile file, IntArrayList list) { for(int i = 0, len = list.size(); i < len; i+=2) { ProgressManager.checkCanceled(); - if (list.getQuick(i + 1) != myHash2) continue; - int offset = list.getQuick(i); + if (list.getInt(i + 1) != myHash2) continue; + int offset = list.getInt(i); if (myFileIndex.isInSourceContent(virtualFile)) { if (!myFileIndex.isInSourceContent(file)) return true; @@ -312,13 +304,13 @@ public class DuplicatesInspectionBase extends LocalInspectionTool { PsiElement target = getPsi(myNode); TextRange rangeInElement = getRangeInElement(myNode); - Integer fragmentStartOffsetInteger = startOffset; - SortedMap map = reportedRanges.subMap(fragmentStartOffsetInteger, endOffset); + int fragmentStartOffsetInteger = startOffset; + Int2ObjectSortedMap map = reportedRanges.subMap(fragmentStartOffsetInteger, endOffset); int newFragmentSize = !map.isEmpty() ? 0:1; - Iterator iterator = map.keySet().iterator(); + IntBidirectionalIterator iterator = map.keySet().iterator(); while(iterator.hasNext()) { - Integer next = iterator.next(); + int next = iterator.nextInt(); iterator.remove(); reportedFiles.remove(next); reportedOffsetInOtherFiles.remove(next); diff --git a/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java b/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java index 14c7b416d1ad..21b21b7b10d3 100644 --- a/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java +++ b/platform/editor-ui-api/src/com/intellij/openapi/editor/InlayModel.java @@ -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.openapi.editor; import com.intellij.openapi.Disposable; @@ -30,7 +30,7 @@ public interface InlayModel { /** * Introduces an inline visual element at a given offset, its width and appearance is defined by the provided renderer. * - * @param relatesToPrecedingText whether element is associated with preceding or following text + * @param relatesToPrecedingText whether element is associated with preceding or following text * (see {@link Inlay#isRelatedToPrecedingText()}) * @return {@code null} if requested element cannot be created, e.g. if corresponding functionality * is not supported by current editor instance. @@ -76,7 +76,7 @@ public interface InlayModel { * Both visible and invisible (due to folding) elements are returned. */ @NotNull - List getInlineElementsInRange(int startOffset, int endOffset); + List> getInlineElementsInRange(int startOffset, int endOffset); /** * Same as {@link #getInlineElementsInRange(int, int)}, but returned list contains only inlays with renderer of given type. @@ -192,7 +192,7 @@ public interface InlayModel { * @see #addAfterLineEndElement(int, boolean, EditorCustomElementRenderer) */ @NotNull - List getAfterLineEndElementsForLogicalLine(int logicalLine); + List> getAfterLineEndElementsForLogicalLine(int logicalLine); /** * When text is inserted at inline element's offset, resulting element's position is determined by its diff --git a/platform/execution-impl/intellij.platform.execution.impl.iml b/platform/execution-impl/intellij.platform.execution.impl.iml index 4c2545dc3f53..4ef27679c50c 100644 --- a/platform/execution-impl/intellij.platform.execution.impl.iml +++ b/platform/execution-impl/intellij.platform.execution.impl.iml @@ -15,5 +15,6 @@ + \ No newline at end of file diff --git a/platform/execution-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java b/platform/execution-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java index ebfdb71d5ce5..b126c7c46b14 100644 --- a/platform/execution-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java +++ b/platform/execution-impl/src/com/intellij/execution/ui/layout/impl/RunnerLayout.java @@ -10,20 +10,15 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; import com.intellij.ui.content.Content; import com.intellij.util.containers.hash.LinkedHashMap; -import java.util.Comparator; -import java.util.HashMap; -import java.util.HashSet; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.Set; -import java.util.TreeSet; -import javax.swing.Icon; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jdom.Element; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; +import java.util.*; + public class RunnerLayout { public static final Key DEFAULT_INDEX = Key.create("RunnerLayoutDefaultIndex"); public static final Key DROP_INDEX = Key.create("RunnerLayoutDropIndex"); @@ -32,7 +27,7 @@ public class RunnerLayout { private final Map myDefaultViews = new HashMap<>(); protected Set myTabs = new TreeSet<>(Comparator.comparingInt(TabImpl::getIndex)); - private final Map myDefaultTabs = new HashMap<>(); + private final Int2ObjectOpenHashMap myDefaultTabs = new Int2ObjectOpenHashMap<>(); protected General myGeneral = new General(); private final Map> myDefaultFocus = new HashMap<>(); diff --git a/platform/lang-api/intellij.platform.lang.iml b/platform/lang-api/intellij.platform.lang.iml index 18f41a6b6bdf..2e44a1114732 100644 --- a/platform/lang-api/intellij.platform.lang.iml +++ b/platform/lang-api/intellij.platform.lang.iml @@ -21,5 +21,6 @@ + \ No newline at end of file diff --git a/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/AbstractCodeStylePropertyMapper.java b/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/AbstractCodeStylePropertyMapper.java index c3747cec0afc..1bd590214a0b 100644 --- a/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/AbstractCodeStylePropertyMapper.java +++ b/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/AbstractCodeStylePropertyMapper.java @@ -1,14 +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.application.options.codeStyle.properties; import com.intellij.openapi.util.AtomicNotNullLazyValue; import com.intellij.psi.codeStyle.CodeStyleSettings; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; import java.lang.reflect.Modifier; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.stream.Collectors; public abstract class AbstractCodeStylePropertyMapper { @@ -25,7 +29,7 @@ public abstract class AbstractCodeStylePropertyMapper { } private Map> createMap() { - Map> accessorMap = new HashMap<>(); + Object2ObjectOpenHashMap> accessorMap = new Object2ObjectOpenHashMap<>(); for (CodeStyleObjectDescriptor descriptor : getSupportedFields()) { addAccessorsFor(accessorMap, descriptor.getCodeStyleObject(), descriptor.getSupportedFields()); } diff --git a/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/ExternalStringAccessor.java b/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/ExternalStringAccessor.java index 5d633639931c..1dcc55156990 100644 --- a/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/ExternalStringAccessor.java +++ b/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/ExternalStringAccessor.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.application.options.codeStyle.properties; import org.jetbrains.annotations.NotNull; @@ -7,7 +7,6 @@ import org.jetbrains.annotations.Nullable; import java.lang.reflect.Field; public abstract class ExternalStringAccessor extends CodeStyleFieldAccessor { - public ExternalStringAccessor(@NotNull Object object, @NotNull Field field) { super(object, field); } diff --git a/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/MagicIntegerConstAccessor.java b/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/MagicIntegerConstAccessor.java index 058e4de6ba28..76021ecae4a9 100644 --- a/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/MagicIntegerConstAccessor.java +++ b/platform/lang-api/src/com/intellij/application/options/codeStyle/properties/MagicIntegerConstAccessor.java @@ -1,7 +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 com.intellij.application.options.codeStyle.properties; -import com.intellij.util.containers.BidirectionalMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -10,7 +12,8 @@ import java.util.ArrayList; import java.util.List; public class MagicIntegerConstAccessor extends ExternalStringAccessor implements CodeStyleChoiceList { - private final BidirectionalMap myValueMap = new BidirectionalMap<>(); + private final Int2ObjectOpenHashMap myValueMap = new Int2ObjectOpenHashMap<>(); + private final Object2ObjectOpenHashMap myValueToKeysMap = new Object2ObjectOpenHashMap<>(); public MagicIntegerConstAccessor(@NotNull Object object, @NotNull Field field, @@ -18,26 +21,26 @@ public class MagicIntegerConstAccessor extends ExternalStringAccessor i String[] strValues) { super(object, field); for (int i = 0; i < Math.min(intValues.length, strValues.length); i ++) { - myValueMap.put(intValues[i], strValues[i]); + String value = strValues[i]; + int intValue = intValues[i]; + myValueMap.put(intValue, value); + myValueToKeysMap.computeIfAbsent(value, __ -> new IntArrayList()).add(intValue); } } - @Nullable @Override - protected final Integer fromExternal(@NotNull String str) { - List keys = myValueMap.getKeysByValue(str); - return keys != null && keys.size() > 0 ? keys.get(0) : null; + protected final @Nullable Integer fromExternal(@NotNull String str) { + IntArrayList keys = myValueToKeysMap.get(str); + return keys != null && keys.size() > 0 ? keys.getInt(0) : null; } - @NotNull @Override - protected final String toExternal(@NotNull Integer value) { - return myValueMap.get(value); + protected final @NotNull String toExternal(@NotNull Integer value) { + return myValueMap.get(value.intValue()); } - @NotNull @Override - public final List getChoices() { + public final @NotNull List getChoices() { return new ArrayList<>(myValueMap.values()); } } diff --git a/platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java b/platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java index 0630c59281e6..77d8a0dc76ad 100644 --- a/platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java +++ b/platform/lang-api/src/com/intellij/execution/testframework/TestIconMapper.java @@ -1,35 +1,19 @@ -/* - * 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.execution.testframework; import com.intellij.execution.testframework.sm.runner.states.TestStateInfo; import com.intellij.icons.AllIcons; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; -import java.util.HashMap; -import java.util.Map; /** * @author Dmitry Avdeev */ -public class TestIconMapper implements PoolOfTestIcons { - - private final static Map magnitudes = new HashMap<>(); +public final class TestIconMapper implements PoolOfTestIcons { + private final static Int2ObjectOpenHashMap magnitudes = new Int2ObjectOpenHashMap<>(); static { for (TestStateInfo.Magnitude value : TestStateInfo.Magnitude.values()) { diff --git a/platform/lang-api/src/com/intellij/formatting/WrapType.java b/platform/lang-api/src/com/intellij/formatting/WrapType.java index f9c0bf1a6e63..d00a0a9133fd 100644 --- a/platform/lang-api/src/com/intellij/formatting/WrapType.java +++ b/platform/lang-api/src/com/intellij/formatting/WrapType.java @@ -1,11 +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 com.intellij.formatting; import com.intellij.psi.codeStyle.CodeStyleSettings; import com.intellij.psi.codeStyle.CommonCodeStyleSettings; - -import java.util.HashMap; -import java.util.Map; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; /** * Defines possible types of a wrap. @@ -40,7 +38,7 @@ public enum WrapType { */ CHOP_DOWN_IF_LONG(CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM); - private static final Map LEGACY_MAPPINGS = new HashMap<>(); + private static final Int2ObjectOpenHashMap LEGACY_MAPPINGS = new Int2ObjectOpenHashMap<>(); static { for (WrapType wrapType : values()) { diff --git a/platform/lang-api/src/com/intellij/psi/codeStyle/extractor/values/Generation.java b/platform/lang-api/src/com/intellij/psi/codeStyle/extractor/values/Generation.java index cbc3e8b8179f..0692af5ea160 100644 --- a/platform/lang-api/src/com/intellij/psi/codeStyle/extractor/values/Generation.java +++ b/platform/lang-api/src/com/intellij/psi/codeStyle/extractor/values/Generation.java @@ -1,20 +1,19 @@ // 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.codeStyle.extractor.values; -import com.intellij.openapi.util.Pair; import com.intellij.psi.codeStyle.extractor.Utils; import com.intellij.psi.codeStyle.extractor.differ.Differ; +import com.intellij.util.IntPair; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; import java.util.Comparator; import java.util.List; -public class Generation { - +public final class Generation { private static final int GENERATION_POOL_SIZE = 45; private static final int MUTATION_PER_GEN = 10; - public static int GEN_COUNT = 40; + public static int GEN_COUNT = 40; private List myGensPool; private int myAge; private final int myParentKind; @@ -75,12 +74,12 @@ public class Generation { } private int reduceToSize(@NotNull Differ differ, int newPoolSize) { - List> ranges = new ArrayList<>(myGensPool.size()); + List ranges = new ArrayList<>(myGensPool.size()); int i = 0; for (final Gens gens : myGensPool) { int range = differ.getDifference(gens); - ranges.add(Pair.create(range, i++)); + ranges.add(new IntPair(range, i++)); if (range == 0) { myAge = GEN_COUNT; newPoolSize = 1; @@ -93,7 +92,7 @@ public class Generation { final ArrayList gensPool = new ArrayList<>(newPoolSize); int count = 0; int worseForward = 0; - for (final Pair pair : ranges) { + for (IntPair pair : ranges) { if (count >= newPoolSize) { break; } diff --git a/platform/lang-impl/intellij.platform.lang.impl.iml b/platform/lang-impl/intellij.platform.lang.impl.iml index 3d282594d8ca..4eaff235d558 100644 --- a/platform/lang-impl/intellij.platform.lang.impl.iml +++ b/platform/lang-impl/intellij.platform.lang.impl.iml @@ -46,5 +46,6 @@ + - + \ No newline at end of file diff --git a/platform/lang-impl/intellij.platform.lang.tests.iml b/platform/lang-impl/intellij.platform.lang.tests.iml index 02f169f08aa2..5f7eb2ea9b59 100644 --- a/platform/lang-impl/intellij.platform.lang.tests.iml +++ b/platform/lang-impl/intellij.platform.lang.tests.iml @@ -37,5 +37,6 @@ + \ No newline at end of file diff --git a/platform/lang-impl/src/com/intellij/codeEditor/printing/ExportToHTMLManager.java b/platform/lang-impl/src/com/intellij/codeEditor/printing/ExportToHTMLManager.java index 0bd3018b21c6..22930eb22aa5 100644 --- a/platform/lang-impl/src/com/intellij/codeEditor/printing/ExportToHTMLManager.java +++ b/platform/lang-impl/src/com/intellij/codeEditor/printing/ExportToHTMLManager.java @@ -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.codeEditor.printing; @@ -18,6 +18,7 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.psi.*; import com.intellij.psi.impl.file.PsiDirectoryFactory; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -134,7 +135,7 @@ class ExportToHTMLManager { @NotNull protected static String doPaint(@NotNull String dirName, @NotNull HTMLTextPainter textPainter, - @Nullable Map refMap) throws IOException { + @Nullable Int2ObjectRBTreeMap refMap) throws IOException { String htmlFile = dirName + File.separator + getHTMLFileName(textPainter.getPsiFile()); try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(htmlFile), StandardCharsets.UTF_8)) { textPainter.paint(refMap, writer, true); @@ -156,11 +157,11 @@ class ExportToHTMLManager { if (!psiFile.isValid()) { return; } - Map refMap = null; + Int2ObjectRBTreeMap refMap = null; for (PrintOption printOption : PrintOption.EP_NAME.getExtensionList()) { final TreeMap map = printOption.collectReferences(psiFile, filesMap); if (map != null) { - refMap = new TreeMap<>(map); + refMap = new Int2ObjectRBTreeMap<>(map); } } diff --git a/platform/lang-impl/src/com/intellij/codeEditor/printing/HTMLTextPainter.java b/platform/lang-impl/src/com/intellij/codeEditor/printing/HTMLTextPainter.java index b261a6c1800e..0e51996e6296 100644 --- a/platform/lang-impl/src/com/intellij/codeEditor/printing/HTMLTextPainter.java +++ b/platform/lang-impl/src/com/intellij/codeEditor/printing/HTMLTextPainter.java @@ -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.codeEditor.printing; import com.intellij.application.options.CodeStyle; @@ -22,6 +22,8 @@ import com.intellij.psi.impl.file.PsiDirectoryFactory; import com.intellij.ui.ColorUtil; import com.intellij.ui.Gray; import com.intellij.ui.JBColor; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; +import it.unimi.dsi.fastutil.ints.IntIterator; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -30,7 +32,10 @@ import java.io.File; import java.io.IOException; import java.io.StringWriter; import java.io.Writer; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; +import java.util.StringTokenizer; public class HTMLTextPainter { private static final Logger LOG = Logger.getInstance(HTMLTextPainter.class); @@ -106,7 +111,7 @@ public class HTMLTextPainter { myFirstLineNumber = firstLineNumber; } - public void paint(@Nullable Map refMap, @NotNull Writer writer, boolean isStandalone) throws IOException { + public void paint(@Nullable Int2ObjectRBTreeMap refMap, @NotNull Writer writer, boolean isStandalone) throws IOException { HighlighterIterator hIterator = myHighlighter.createIterator(myOffset); if (hIterator.atEnd()) { return; @@ -114,16 +119,15 @@ public class HTMLTextPainter { lineCount = myFirstLineNumber; TextAttributes prevAttributes = null; - Iterator refKeys = null; - + IntIterator refKeys = null; int refOffset = -1; PsiReference ref = null; if (refMap != null) { refKeys = refMap.keySet().iterator(); if (refKeys.hasNext()) { - Integer key = refKeys.next(); + int key = refKeys.nextInt(); ref = refMap.get(key); - refOffset = key.intValue(); + refOffset = key; } } @@ -201,9 +205,9 @@ public class HTMLTextPainter { writer.write(""); referenceEnd = -1; if (refKeys.hasNext()) { - Integer key = refKeys.next(); + int key = refKeys.nextInt(); ref = refMap.get(key); - refOffset = key.intValue(); + refOffset = key; } } hIterator.advance(); diff --git a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java index d19472ce4537..b29bef42f162 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/hint/ParameterInfoComponent.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.hint; @@ -24,6 +24,9 @@ import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.accessibility.AccessibleContextUtil; import com.intellij.xml.util.XmlStringUtil; +import it.unimi.dsi.fastutil.ints.Int2IntMap; +import it.unimi.dsi.fastutil.ints.Int2IntMaps; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -519,7 +522,7 @@ public class ParameterInfoComponent extends JPanel { } } - private class OneLineComponent extends JPanel { + private final class OneLineComponent extends JPanel { JLabel myLabel = new JLabel("", SwingConstants.LEFT); private OneLineComponent(){ @@ -586,7 +589,7 @@ public class ParameterInfoComponent extends JPanel { // flagsMap is supposed to use TEXT_RANGE_COMPARATOR private String buildLabelText(@NotNull final String text, @NotNull final TreeMap flagsMap) { final StringBuilder labelText = new StringBuilder(text); - final Map faultMap = new HashMap<>(); + final Int2IntOpenHashMap faultMap = new Int2IntOpenHashMap(); for (Map.Entry entry : flagsMap.entrySet()) { final TextRange highlightRange = entry.getKey(); @@ -599,10 +602,10 @@ public class ParameterInfoComponent extends JPanel { int startOffset = highlightRange.getStartOffset(); int endOffset = highlightRange.getEndOffset() + tag.length(); - for (Map.Entry entry1 : faultMap.entrySet()) { - if (entry1.getKey() <= highlightRange.getStartOffset()) { - startOffset += entry1.getValue(); - endOffset += entry1.getValue(); + for (Int2IntMap.Entry entry1 : Int2IntMaps.fastIterable(faultMap)) { + if (entry1.getIntKey() <= highlightRange.getStartOffset()) { + startOffset += entry1.getIntValue(); + endOffset += entry1.getIntValue(); } } diff --git a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java index 76fbfb3c1640..f1a38e43a50f 100644 --- a/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java +++ b/platform/lang-impl/src/com/intellij/codeInsight/lookup/impl/LookupCellRenderer.java @@ -3,8 +3,10 @@ package com.intellij.codeInsight.lookup.impl; import com.google.common.annotations.VisibleForTesting; -import com.intellij.codeInsight.lookup.*; -import com.intellij.openapi.diagnostic.Logger; +import com.intellij.codeInsight.lookup.LookupElement; +import com.intellij.codeInsight.lookup.LookupElementPresentation; +import com.intellij.codeInsight.lookup.LookupElementRenderer; +import com.intellij.codeInsight.lookup.LookupFocusDegree; import com.intellij.openapi.editor.Editor; import com.intellij.openapi.editor.colors.EditorColorsScheme; import com.intellij.openapi.editor.colors.EditorColorsUtil; @@ -29,13 +31,16 @@ import com.intellij.util.ui.EmptyIcon; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; import com.intellij.util.ui.accessibility.AccessibleContextUtil; +import it.unimi.dsi.fastutil.ints.Int2BooleanOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.border.Border; import java.awt.*; -import java.util.*; +import java.util.HashSet; +import java.util.Objects; +import java.util.Set; import static com.intellij.codeInsight.documentation.DocumentationComponent.COLOR_KEY; @@ -43,9 +48,7 @@ import static com.intellij.codeInsight.documentation.DocumentationComponent.COLO * @author peter * @author Konstantin Bulenkov */ -public class LookupCellRenderer implements ListCellRenderer { - private static final Logger LOG = Logger.getInstance(LookupCellRenderer.class); - +public final class LookupCellRenderer implements ListCellRenderer { private Icon myEmptyIcon = EmptyIcon.ICON_0; private final Font myNormalFont; private final Font myBoldFont; @@ -66,7 +69,7 @@ public class LookupCellRenderer implements ListCellRenderer { private final SimpleColoredComponent myTailComponent; private final SimpleColoredComponent myTypeLabel; private final LookupPanel myPanel; - private final Map mySelected = new HashMap<>(); + private final Int2BooleanOpenHashMap mySelected = new Int2BooleanOpenHashMap(); private static final String ELLIPSIS = "\u2026"; private int myMaxWidth = -1; @@ -525,7 +528,7 @@ public class LookupCellRenderer implements ListCellRenderer { return 0; } - private static class MySimpleColoredComponent extends SimpleColoredComponent { + private static final class MySimpleColoredComponent extends SimpleColoredComponent { private MySimpleColoredComponent() { setFocusBorderAroundIcon(true); } diff --git a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java index 839454a7a209..ddd7d33db232 100644 --- a/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.java +++ b/platform/lang-impl/src/com/intellij/refactoring/rename/RenameUtil.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.refactoring.rename; @@ -38,13 +38,15 @@ import com.intellij.usageView.UsageInfoFactory; import com.intellij.util.IncorrectOperationException; import com.intellij.util.Processor; import com.intellij.util.containers.MultiMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.*; -public class RenameUtil { +public final class RenameUtil { private static final Logger LOG = Logger.getInstance(RenameUtil.class); private RenameUtil() { @@ -288,7 +290,7 @@ public class RenameUtil { public static void renameNonCodeUsages(@NotNull Project project, NonCodeUsageInfo @NotNull [] usages) { PsiDocumentManager.getInstance(project).commitAllDocuments(); - Map> docsToOffsetsMap = new HashMap<>(); + Object2ObjectOpenHashMap> docsToOffsetsMap = new Object2ObjectOpenHashMap<>(); final PsiDocumentManager psiDocumentManager = PsiDocumentManager.getInstance(project); for (NonCodeUsageInfo usage : usages) { PsiElement element = usage.getElement(); @@ -315,9 +317,9 @@ public class RenameUtil { } int fileOffset = replaceRange.getStartOffset(); - Map offsetMap = docsToOffsetsMap.get(document); + Int2ObjectOpenHashMap offsetMap = docsToOffsetsMap.get(document); if (offsetMap == null) { - offsetMap = new HashMap<>(); + offsetMap = new Int2ObjectOpenHashMap<>(); docsToOffsetsMap.put(document, offsetMap); } final UsageOffset substitution = new UsageOffset(fileOffset, fileOffset + rangeInElement.getLength(), usage.newText); diff --git a/platform/lvcs-impl/intellij.platform.lvcs.impl.iml b/platform/lvcs-impl/intellij.platform.lvcs.impl.iml index 360c145e01a4..31efcf89d6a7 100644 --- a/platform/lvcs-impl/intellij.platform.lvcs.impl.iml +++ b/platform/lvcs-impl/intellij.platform.lvcs.impl.iml @@ -14,6 +14,7 @@ + diff --git a/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/SelectionCalculator.java b/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/SelectionCalculator.java index cdd9aac71d22..a0e352e256e9 100644 --- a/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/SelectionCalculator.java +++ b/platform/lvcs-impl/src/com/intellij/history/integration/ui/models/SelectionCalculator.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2009 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.history.integration.ui.models; import com.intellij.diff.Block; @@ -21,20 +6,19 @@ import com.intellij.history.core.Content; import com.intellij.history.core.revisions.Revision; import com.intellij.history.core.tree.Entry; import com.intellij.history.integration.IdeaGateway; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.Nullable; -import java.util.HashMap; import java.util.List; -import java.util.Map; -public class SelectionCalculator { +public final class SelectionCalculator { private static final Block EMPTY_BLOCK = new Block("", 0, 0); - + private final IdeaGateway myGateway; private final List myRevisions; private final int myFromLine; private final int myToLine; - private final Map myCache = new HashMap<>(); + private final Int2ObjectOpenHashMap myCache = new Int2ObjectOpenHashMap<>(); public SelectionCalculator(IdeaGateway gw, List rr, int fromLine, int toLine) { myGateway = gw; @@ -71,7 +55,7 @@ public class SelectionCalculator { Block result; if (content == null) { - result = EMPTY_BLOCK; + result = EMPTY_BLOCK; } else if (revisionIndex == 0) { result = new Block(content, myFromLine, myToLine + 1); } diff --git a/platform/platform-api/intellij.platform.ide.iml b/platform/platform-api/intellij.platform.ide.iml index 9db5af9f8498..c69df393e493 100644 --- a/platform/platform-api/intellij.platform.ide.iml +++ b/platform/platform-api/intellij.platform.ide.iml @@ -45,5 +45,6 @@ + \ No newline at end of file diff --git a/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizardEx.java b/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizardEx.java index f9a7ec6f033e..38bc05055dc7 100644 --- a/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizardEx.java +++ b/platform/platform-api/src/com/intellij/ide/wizard/AbstractWizardEx.java @@ -1,19 +1,4 @@ -/* - * Copyright 2000-2010 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.ide.wizard; import com.intellij.openapi.project.Project; @@ -21,6 +6,7 @@ import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.wm.IdeFocusManager; import com.intellij.ui.JBCardLayout; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -29,10 +15,9 @@ import java.util.List; import java.util.Map; public class AbstractWizardEx extends AbstractWizard { - private final String myTitle; private final Map myStepId2Index = new HashMap<>(); - private final Map myIndex2Step = new HashMap<>(); + private final Int2ObjectOpenHashMap myIndex2Step = new Int2ObjectOpenHashMap<>(); public AbstractWizardEx(String title, @Nullable Project project, List steps) { super(title, project); diff --git a/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java b/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java index 5dd5280a1f1e..f78ccb2c91c6 100644 --- a/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java +++ b/platform/platform-api/src/com/intellij/openapi/MnemonicHelper.java @@ -12,6 +12,7 @@ import com.intellij.ui.components.JBOptionButton; import com.intellij.util.ArrayUtil; import com.intellij.util.ui.DialogUtil; import com.intellij.util.ui.UIUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.intellij.lang.annotations.MagicConstant; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -25,8 +26,6 @@ import java.awt.event.InputEvent; import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; import java.util.function.IntPredicate; /** @@ -60,7 +59,7 @@ public final class MnemonicHelper extends ComponentTreeWatcher { } }; - private Map myMnemonics; + private Int2ObjectOpenHashMap myMnemonics; /** * @see #init(Component) @@ -137,12 +136,12 @@ public final class MnemonicHelper extends ComponentTreeWatcher { public void checkForDuplicateMnemonics(int mnemonic, String text) { if (mnemonic == 0) return; - if (myMnemonics == null) myMnemonics = new HashMap<>(); - final String other = myMnemonics.get(Integer.valueOf(mnemonic)); + if (myMnemonics == null) myMnemonics = new Int2ObjectOpenHashMap<>(); + final String other = myMnemonics.get(mnemonic); if (other != null && !other.equals(text)) { LOG.error("conflict: multiple components with mnemonic '" + (char)mnemonic + "' seen on '" + text + "' and '" + other + "'"); } - myMnemonics.put(Integer.valueOf(mnemonic), text); + myMnemonics.put(mnemonic, text); } /** diff --git a/platform/platform-api/src/com/intellij/util/IntPair.java b/platform/platform-api/src/com/intellij/util/IntPair.java new file mode 100644 index 000000000000..81d259010fd1 --- /dev/null +++ b/platform/platform-api/src/com/intellij/util/IntPair.java @@ -0,0 +1,31 @@ +// 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; + +public final class IntPair { + public final int first; + public final int second; + + public IntPair(int first, int second) { + this.first = first; + this.second = second; + } + + @Override + public int hashCode() { + return 31 * first + second; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + IntPair that = (IntPair)o; + return first == that.first && second == that.second; + } + + @Override + public String toString() { + return "first=" + first + ", second=" + second; + } +} diff --git a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java index da00d2f8c221..45bee9dd4549 100644 --- a/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.java +++ b/platform/platform-api/src/com/intellij/util/ui/update/MergingUpdateQueue.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.ui.update; import com.intellij.ide.UiActivity; @@ -13,6 +13,7 @@ import com.intellij.util.Alarm; import com.intellij.util.AlarmFactory; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.UIUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -22,7 +23,6 @@ import javax.swing.*; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.TreeMap; /** * Use this class to postpone task execution and optionally merge identical tasks. This is needed e.g. to reflect in UI status of some @@ -39,7 +39,7 @@ public class MergingUpdateQueue implements Runnable, Disposable, Activatable { private volatile boolean myActive; private volatile boolean mySuspended; - private final Map> myScheduledUpdates = new TreeMap<>(); + private final Int2ObjectRBTreeMap> myScheduledUpdates = new Int2ObjectRBTreeMap<>(); private final Alarm myWaiterForMerge; diff --git a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java index 0701135ada1c..ad73f0863a8d 100644 --- a/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java +++ b/platform/platform-impl/src/com/intellij/ide/ui/search/SearchUtil.java @@ -15,6 +15,10 @@ import com.intellij.ui.TabbedPaneWrapper; import com.intellij.util.CollectConsumer; import com.intellij.util.ReflectionUtil; import com.intellij.util.containers.ContainerUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; +import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -38,7 +42,7 @@ public final class SearchUtil { private static final Pattern NON_WORD_PATTERN = Pattern.compile("[\\W&&[^\\p{Punct}\\p{Blank}]]"); public static final String HIGHLIGHT_WITH_BORDER = "searchUtil.highlightWithBorder"; - public static final String STYLE_END = ""; + private static final String STYLE_END = ""; private SearchUtil() { } @@ -77,8 +81,7 @@ public final class SearchUtil { final Configurable unwrapped = unwrapConfigurable(configurable); if (unwrapped instanceof CompositeConfigurable) { unwrapped.disposeUIResources(); - //noinspection unchecked - final List children = ((CompositeConfigurable)unwrapped).getConfigurables(); + final List children = ((CompositeConfigurable)unwrapped).getConfigurables(); for (final UnnamedConfigurable child : children) { final Set childConfigurableOptions = new TreeSet<>(); options.put(new SearchableConfigurableAdapter(searchableConfigurable, child), childConfigurableOptions); @@ -152,7 +155,7 @@ public final class SearchUtil { processUILabel(label, configurableOptions, path); } else if (component instanceof JComboBox) { - List labels = getItemsFromComboBox((JComboBox)component); + List labels = getItemsFromComboBox((JComboBox)component); for (String each : labels) { processUILabel(each, configurableOptions, path); } @@ -213,20 +216,20 @@ public final class SearchUtil { } @NotNull - public static List getItemsFromComboBox(@NotNull JComboBox comboBox) { - ListCellRenderer renderer = comboBox.getRenderer(); + private static List getItemsFromComboBox(@NotNull JComboBox comboBox) { + @SuppressWarnings("unchecked") + ListCellRenderer renderer = (ListCellRenderer)comboBox.getRenderer(); if (renderer == null) { renderer = new DefaultListCellRenderer(); } - JList jList = new BasicComboPopup(comboBox).getList(); + JList jList = new BasicComboPopup(comboBox).getList(); List result = new ArrayList<>(); int count = comboBox.getItemCount(); for (int i = 0; i < count; i++) { Object value = comboBox.getItemAt(i); - //noinspection unchecked Component labelComponent = renderer.getListCellRendererComponent(jList, value, i, false, false); String label = getLabelFromComponent(labelComponent); if (label != null) { @@ -289,7 +292,7 @@ public final class SearchUtil { } } else if (rootComponent instanceof JComboBox) { - List labels = getItemsFromComboBox(((JComboBox)rootComponent)); + List labels = getItemsFromComboBox(((JComboBox)rootComponent)); if (ContainerUtil.exists(labels, it -> isComponentHighlighted(it, option, force, configurable))) { highlightComponent(rootComponent, option); return true; // do not visit children of highlighted component @@ -467,24 +470,25 @@ public final class SearchUtil { if (filter == null || filter.length() == 0) { textRenderer.append(text, new SimpleTextAttributes(background, foreground, JBColor.RED, style)); } - else { //markup - final HashSet quoted = new HashSet<>(); + else { + //markup + ObjectOpenHashSet quoted = new ObjectOpenHashSet<>(); filter = processFilter(quoteStrictOccurrences(text, filter), quoted); - final TreeMap indx = new TreeMap<>(); + final Int2ObjectRBTreeMap indexToString = new Int2ObjectRBTreeMap<>(); for (String stripped : quoted) { int beg = 0; int idx; while ((idx = StringUtil.indexOfIgnoreCase(text, stripped, beg)) != -1) { - indx.put(idx, text.substring(idx, idx + stripped.length())); + indexToString.put(idx, text.substring(idx, idx + stripped.length())); beg = idx + stripped.length(); } } final List selectedWords = new ArrayList<>(); int pos = 0; - for (Integer index : indx.keySet()) { - final String stripped = indx.get(index); - final int start = index.intValue(); + for (Int2ObjectMap.Entry entry : Int2ObjectMaps.fastIterable(indexToString)) { + String stripped = entry.getValue(); + int start = entry.getIntKey(); if (pos > start) { final String highlighted = selectedWords.get(selectedWords.size() - 1); if (highlighted.length() < stripped.length()) { @@ -556,7 +560,7 @@ public final class SearchUtil { return keySetList; } - public static String processFilter(String filter, Set quoted) { + private static String processFilter(String filter, Set quoted) { StringBuilder withoutQuoted = new StringBuilder(); int beg = 0; final Matcher matcher = QUOTED.matcher(filter); diff --git a/platform/platform-impl/src/com/intellij/idea/SocketLock.java b/platform/platform-impl/src/com/intellij/idea/SocketLock.java index 7ed16be793e7..f71b4c33ce69 100644 --- a/platform/platform-impl/src/com/intellij/idea/SocketLock.java +++ b/platform/platform-impl/src/com/intellij/idea/SocketLock.java @@ -19,6 +19,9 @@ import io.netty.buffer.ByteBuf; import io.netty.buffer.ByteBufOutputStream; import io.netty.channel.ChannelHandler; import io.netty.channel.ChannelHandlerContext; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMaps; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -149,13 +152,13 @@ public final class SocketLock { lockPortFiles(); - Map> portToPath = new HashMap<>(); + Int2ObjectOpenHashMap> portToPath = new Int2ObjectOpenHashMap<>(2); readPort(myConfigPath, portToPath); readPort(mySystemPath, portToPath); if (!portToPath.isEmpty()) { args = JetBrainsProtocolHandler.checkForJetBrainsProtocolCommand(args); - for (Map.Entry> entry : portToPath.entrySet()) { - Map.Entry status = tryActivate(entry.getKey(), entry.getValue(), args); + for (Int2ObjectMap.Entry> entry : Int2ObjectMaps.fastIterable(portToPath)) { + Map.Entry status = tryActivate(entry.getIntKey(), entry.getValue(), args); if (status.getKey() != ActivationStatus.NO_INSTANCE) { log("exit: lock(): " + status.getValue()); unlockPortFiles(); @@ -248,9 +251,15 @@ public final class SocketLock { } } - private static void readPort(@NotNull Path dir, @NotNull Map> portToPath) { + private static void readPort(@NotNull Path dir, @NotNull Int2ObjectOpenHashMap> portToPath) { try { - portToPath.computeIfAbsent(Integer.parseInt(readOneLine(dir.resolve(PORT_FILE))), it -> new ArrayList<>()).add(dir.toString()); + int port = Integer.parseInt(readOneLine(dir.resolve(PORT_FILE))); + List list = portToPath.get(port); + if (list == null) { + list = new ArrayList<>(); + portToPath.put(port, list); + } + list.add(dir.toString()); } catch (NoSuchFileException ignore) { } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingAnchorsOverlayStrategy.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingAnchorsOverlayStrategy.java index 681cdae0e2b0..3650aed222b2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingAnchorsOverlayStrategy.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/FoldingAnchorsOverlayStrategy.java @@ -1,29 +1,14 @@ -/* - * Copyright 2000-2013 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.openapi.editor.impl; import com.intellij.openapi.editor.FoldRegion; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import java.util.Collection; -import java.util.HashMap; import java.util.List; -import java.util.Map; -class FoldingAnchorsOverlayStrategy { +final class FoldingAnchorsOverlayStrategy { private final EditorImpl myEditor; FoldingAnchorsOverlayStrategy(EditorImpl editor) { @@ -34,7 +19,7 @@ class FoldingAnchorsOverlayStrategy { Collection getAnchorsToDisplay(int firstVisibleOffset, int lastVisibleOffset, @NotNull List activeFoldRegions) { - Map result = new HashMap<>(); + Int2ObjectOpenHashMap result = new Int2ObjectOpenHashMap<>(); FoldRegion[] visibleFoldRegions = myEditor.getFoldingModel().fetchVisible(); if (visibleFoldRegions != null) { for (FoldRegion region : visibleFoldRegions) { @@ -78,7 +63,7 @@ class FoldingAnchorsOverlayStrategy { return result.values(); } - private static void tryAdding(@NotNull Map resultsMap, + private static void tryAdding(@NotNull Int2ObjectOpenHashMap resultsMap, @NotNull FoldRegion region, int visualLine, int visualHeight, diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IndentsModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IndentsModelImpl.java index 7029165b7615..fc9f3d8fb123 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/IndentsModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/IndentsModelImpl.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. /* * @author max @@ -8,17 +8,16 @@ package com.intellij.openapi.editor.impl; import com.intellij.openapi.editor.IndentGuideDescriptor; import com.intellij.openapi.editor.IndentsModel; import com.intellij.openapi.editor.LogicalPosition; +import com.intellij.util.IntPair; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; -public class IndentsModelImpl implements IndentsModel { - - private final Map myIndentsByLines = new HashMap<>(); - private List myIndents = new ArrayList<>(); +public final class IndentsModelImpl implements IndentsModel { + private final Object2ObjectOpenHashMap myIndentsByLines = new Object2ObjectOpenHashMap<>(); + private List myIndents = new ArrayList<>(); @NotNull private final EditorImpl myEditor; public IndentsModelImpl(@NotNull EditorImpl editor) { @@ -59,34 +58,4 @@ public class IndentsModelImpl implements IndentsModel { myIndentsByLines.put(new IntPair(descriptor.startLine, descriptor.endLine), descriptor); } } - - private static class IntPair { - - private final int start; - private final int end; - - IntPair(int start, int end) { - this.start = start; - this.end = end; - } - - @Override - public int hashCode() { - return 31 * start + end; - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; - - IntPair that = (IntPair)o; - return start == that.start && end == that.end; - } - - @Override - public String toString() { - return "start=" + start + ", end=" + end; - } - } } diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java index 91351cf5fe32..e799687634b2 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/InlayModelImpl.java @@ -52,7 +52,7 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, boolean myMoveInProgress; boolean myPutMergedIntervalsAtBeginning; private boolean myConsiderCaretPositionOnDocumentUpdates = true; - private List myInlaysAtCaret; + private List> myInlaysAtCaret; private boolean myInBatchMode; InlayModelImpl(@NotNull EditorImpl editor) { @@ -74,7 +74,7 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, if (myInBatchMode) LOG.error("Document shouldn't be changed during batch inlay operation"); int offset = event.getOffset(); if (myConsiderCaretPositionOnDocumentUpdates && event.getOldLength() == 0 && offset == myEditor.getCaretModel().getOffset()) { - List inlays = getInlineElementsInRange(offset, offset); + List> inlays = getInlineElementsInRange(offset, offset); int inlayCount = inlays.size(); if (inlayCount > 0) { VisualPosition inlaysStartPosition = myEditor.offsetToVisualPosition(offset, false, false); @@ -162,17 +162,15 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, @NotNull @Override - public List getInlineElementsInRange(int startOffset, int endOffset) { - List range = - getElementsInRange(myInlineElementsTree, startOffset, endOffset, inlay -> true, INLINE_ELEMENTS_COMPARATOR); + public List> getInlineElementsInRange(int startOffset, int endOffset) { //noinspection unchecked - return (List)range; + return getElementsInRange(myInlineElementsTree, startOffset, endOffset, inlay -> true, INLINE_ELEMENTS_COMPARATOR); } @NotNull @Override public List> getInlineElementsInRange(int startOffset, int endOffset, @NotNull Class type) { - List range = + List> range = getElementsInRange(myInlineElementsTree, startOffset, endOffset, inlay -> type.isInstance(inlay.myRenderer), INLINE_ELEMENTS_COMPARATOR); //noinspection unchecked @@ -197,11 +195,11 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, return (List)range; } - private static List getElementsInRange(@NotNull IntervalTreeImpl tree, - int startOffset, - int endOffset, - Predicate predicate, - Comparator comparator) { + private static > List getElementsInRange(@NotNull IntervalTreeImpl tree, + int startOffset, + int endOffset, + Predicate predicate, + Comparator comparator) { List result = new ArrayList<>(); tree.processOverlappingWith(startOffset, endOffset, inlay -> { if (predicate.test(inlay)) result.add(inlay); @@ -290,7 +288,7 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, @Override public Inlay getInlineElementAt(@NotNull VisualPosition visualPosition) { int offset = myEditor.visualPositionToOffset(visualPosition); - List inlays = getInlineElementsInRange(offset, offset); + List> inlays = getInlineElementsInRange(offset, offset); if (inlays.isEmpty()) return null; VisualPosition inlayStartPosition = myEditor.offsetToVisualPosition(offset, false, false); if (visualPosition.line != inlayStartPosition.line) return null; @@ -353,12 +351,12 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, } if (hasInlineElements) { int offset = location.getOffset(); - List inlays = getInlineElementsInRange(offset, offset); + List> inlays = getInlineElementsInRange(offset, offset); if (!inlays.isEmpty()) { VisualPosition startVisualPosition = myEditor.offsetToVisualPosition(offset); Point inlayPoint = myEditor.visualPositionToXY(startVisualPosition); if (point.y < inlayPoint.y || point.y >= inlayPoint.y + myEditor.getLineHeight()) return null; - Inlay inlay = findInlay(inlays, point.x, inlayPoint.x); + Inlay inlay = findInlay(inlays, point.x, inlayPoint.x); if (inlay != null) return inlay; } } @@ -366,12 +364,12 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, int offset = location.getOffset(); int logicalLine = myEditor.getDocument().getLineNumber(offset); if (offset == myEditor.getDocument().getLineEndOffset(logicalLine) && !myEditor.getFoldingModel().isOffsetCollapsed(offset)) { - List inlays = myEditor.getInlayModel().getAfterLineEndElementsForLogicalLine(logicalLine); + List> inlays = myEditor.getInlayModel().getAfterLineEndElementsForLogicalLine(logicalLine); if (!inlays.isEmpty()) { Rectangle bounds = inlays.get(0).getBounds(); assert bounds != null; if (point.y < bounds.y || point.y >= bounds.y + bounds.height) return null; - Inlay inlay = findInlay(inlays, point.x, bounds.x); + Inlay inlay = findInlay(inlays, point.x, bounds.x); if (inlay != null) return inlay; } } @@ -379,7 +377,7 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, return null; } - private static Inlay findInlay(List inlays, int x, int startX) { + private static Inlay findInlay(List> inlays, int x, int startX) { for (Inlay inlay : inlays) { int endX = startX + inlay.getWidthInPixels(); if (x >= startX && x < endX) return inlay; @@ -411,7 +409,7 @@ public class InlayModelImpl implements InlayModel, PrioritizedDocumentListener, @NotNull @Override - public List getAfterLineEndElementsForLogicalLine(int logicalLine) { + public List> getAfterLineEndElementsForLogicalLine(int logicalLine) { DocumentEx document = myEditor.getDocument(); if (!hasAfterLineEndElements() || logicalLine < 0 || logicalLine > 0 && logicalLine >= document.getLineCount()) { return Collections.emptyList(); diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java index 0366c3a31b23..9b71f4b62c64 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorPainter.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.editor.impl.view; import com.intellij.openapi.editor.*; @@ -14,7 +14,6 @@ import com.intellij.openapi.editor.impl.*; import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType; import com.intellij.openapi.editor.markup.*; import com.intellij.openapi.editor.markup.TextAttributesEffectsBuilder.EffectDescriptor; -import com.intellij.openapi.util.Couple; import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.wm.impl.IdeBackgroundUtil; @@ -27,16 +26,14 @@ import com.intellij.ui.paint.LinePainter2D; import com.intellij.ui.paint.PaintUtil; import com.intellij.ui.scale.JBUIScale; import com.intellij.ui.scale.ScaleContext; -import com.intellij.util.DocumentUtil; -import com.intellij.util.ObjectUtils; -import com.intellij.util.Processor; -import com.intellij.util.SmartList; +import com.intellij.util.*; import com.intellij.util.containers.PeekableIterator; import com.intellij.util.containers.PeekableIteratorWrapper; import com.intellij.util.text.CharArrayUtil; import com.intellij.util.ui.UIUtil; import gnu.trove.TFloatArrayList; import gnu.trove.TIntObjectHashMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.Contract; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -106,7 +103,7 @@ public class EditorPainter implements TextDrawingCallback { return - Session.getTabGap(Session.getWhiteSpaceScale(editor)) / 2; } - private static class Session { + private static final class Session { private final EditorView myView; private final EditorImpl myEditor; private final Document myDocument; @@ -125,7 +122,7 @@ public class EditorPainter implements TextDrawingCallback { private final int mySeparatorHighlightersEndOffset; private final ClipDetector myClipDetector; private final IterationState.CaretData myCaretData; - private final Map> myVirtualSelectionMap; + private final Int2ObjectOpenHashMap myVirtualSelectionMap; private final TIntObjectHashMap> myExtensionData = new TIntObjectHashMap<>(); // key is visual line private final TIntObjectHashMap myBetweenLinesAttributes = new TIntObjectHashMap<>(); // key is bottom visual line private final int myLineHeight; @@ -478,8 +475,8 @@ public class EditorPainter implements TextDrawingCallback { } } - private static Map> createVirtualSelectionMap(Editor editor, int startVisualLine, int endVisualLine) { - HashMap> map = new HashMap<>(); + private static @NotNull Int2ObjectOpenHashMap createVirtualSelectionMap(Editor editor, int startVisualLine, int endVisualLine) { + Int2ObjectOpenHashMap map = new Int2ObjectOpenHashMap<>(); for (Caret caret : editor.getCaretModel().getAllCarets()) { if (caret.hasSelection()) { VisualPosition selectionStart = caret.getSelectionStartPosition(); @@ -487,7 +484,7 @@ public class EditorPainter implements TextDrawingCallback { if (selectionStart.line == selectionEnd.line) { int line = selectionStart.line; if (line >= startVisualLine && line <= endVisualLine) { - map.put(line, Couple.of(selectionStart.column, selectionEnd.column)); + map.put(line, new IntPair(selectionStart.column, selectionEnd.column)); } } } @@ -496,7 +493,7 @@ public class EditorPainter implements TextDrawingCallback { } private void paintVirtualSelectionIfNecessary(int visualLine, int columnStart, float xStart, int y) { - Couple selectionRange = myVirtualSelectionMap.get(visualLine); + IntPair selectionRange = myVirtualSelectionMap.get(visualLine); if (selectionRange == null || selectionRange.second <= columnStart) return; float startX = selectionRange.first <= columnStart ? xStart @@ -1199,7 +1196,7 @@ public class EditorPainter implements TextDrawingCallback { caret.getSelectionStartPosition().line < bottomVisualLine && bottomVisualLine <= caret.getSelectionEndPosition().line; } - class MyProcessor implements Processor { + final class MyProcessor implements Processor { private int layer; private Color backgroundColor; @@ -1523,7 +1520,7 @@ public class EditorPainter implements TextDrawingCallback { return view.getEditor().isRightAligned() ? new RightAligned(view) : new LeftAligned(view); } - class LeftAligned implements XCorrector { + final class LeftAligned implements XCorrector { private final EditorView myView; private final int myLeftInset; @@ -1593,7 +1590,7 @@ public class EditorPainter implements TextDrawingCallback { } } - class RightAligned implements XCorrector { + final class RightAligned implements XCorrector { private final EditorView myView; private RightAligned(@NotNull EditorView view) { @@ -1662,7 +1659,7 @@ public class EditorPainter implements TextDrawingCallback { } } - private static class LineExtensionData { + private static final class LineExtensionData { private final LineExtensionInfo info; private final LineLayout layout; @@ -1672,7 +1669,7 @@ public class EditorPainter implements TextDrawingCallback { } } - private static class MarginPositions { + private static final class MarginPositions { private final float[] x; private final int[] y; diff --git a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java index 6eb2b0c0abd7..7f416fcb336f 100644 --- a/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java +++ b/platform/platform-impl/src/com/intellij/openapi/editor/impl/view/EditorSizeManager.java @@ -15,11 +15,11 @@ import com.intellij.openapi.editor.impl.*; import com.intellij.openapi.editor.impl.softwrap.SoftWrapDrawingType; import com.intellij.openapi.editor.impl.softwrap.mapping.IncrementalCacheUpdateEvent; import com.intellij.openapi.editor.impl.softwrap.mapping.SoftWrapAwareDocumentParsingListenerAdapter; -import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.TextRange; import com.intellij.util.DocumentEventUtil; import com.intellij.util.DocumentUtil; +import com.intellij.util.IntPair; import gnu.trove.TIntArrayList; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -33,7 +33,7 @@ import java.util.stream.Stream; /** * Calculates width (in pixels) of editor contents. */ -class EditorSizeManager implements PrioritizedDocumentListener, Disposable, FoldingListener, InlayModel.Listener, Dumpable { +final class EditorSizeManager implements PrioritizedDocumentListener, Disposable, FoldingListener, InlayModel.Listener, Dumpable { private static final Logger LOG = Logger.getInstance(EditorSizeManager.class); private static final int UNKNOWN_WIDTH = Integer.MAX_VALUE; @@ -71,7 +71,7 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold private final List myDeferredRanges = new ArrayList<>(); private boolean myWidestBlockInlayValid; - private Inlay myWidestBlockInlay; + private Inlay myWidestBlockInlay; private final SoftWrapAwareDocumentParsingListenerAdapter mySoftWrapChangeListener = new SoftWrapAwareDocumentParsingListenerAdapter() { @Override @@ -213,7 +213,7 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold reset(); } - private void onLineInlayUpdate(@NotNull Inlay inlay) { + private void onLineInlayUpdate(@NotNull Inlay inlay) { if (myDuringDocumentUpdate) { if (inlay.getPlacement() == Inlay.Placement.AFTER_LINE_END) { myAfterLineEndInlayUpdated = true; @@ -327,7 +327,7 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold assert !myEditor.getInlayModel().isInBatchMode(); boolean needFullScan = true; if (myStartInvalidLine <= myEndInvalidLine && (myEndInvalidLine - myStartInvalidLine) < SPECIFIC_LINES_RECALC_THRESHOLD ) { - Pair pair = calculateTextPreferredWidth(myStartInvalidLine, myEndInvalidLine); + IntPair pair = calculateTextPreferredWidth(myStartInvalidLine, myEndInvalidLine); needFullScan = pair.first < myWidthInPixels && myStartInvalidLine <= myWidthDefiningLineNumber && myWidthDefiningLineNumber <= myEndInvalidLine; if (pair.first >= myWidthInPixels) { @@ -336,7 +336,7 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold } } if (needFullScan) { - Pair pair = calculateTextPreferredWidth(0, Integer.MAX_VALUE); + IntPair pair = calculateTextPreferredWidth(0, Integer.MAX_VALUE); myWidthInPixels = pair.first; myWidthDefiningLineNumber = pair.second; } @@ -374,8 +374,10 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold } // first number is the width, second number is the largest visual line number - private Pair calculateTextPreferredWidth(int startVisualLine, int endVisualLine) { - if (checkDirty()) return Pair.pair(1, 0); + private IntPair calculateTextPreferredWidth(int startVisualLine, int endVisualLine) { + if (checkDirty()) { + return new IntPair(1, 0); + } assertValidState(); VisualLinesIterator iterator = new VisualLinesIterator(myEditor, startVisualLine); int maxWidth = 0; @@ -389,7 +391,7 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold if (iterator.getVisualLine() >= endVisualLine) break; iterator.advance(); } - return Pair.create(maxWidth, largestLineNumber); + return new IntPair(maxWidth, largestLineNumber); } int getVisualLineWidth(VisualLinesIterator visualLinesIterator, boolean allowQuickCalculation) { @@ -431,10 +433,10 @@ class EditorSizeManager implements PrioritizedDocumentListener, Disposable, Fold x += myEditor.getSoftWrapModel().getMinDrawingWidthInPixels(SoftWrapDrawingType.BEFORE_SOFT_WRAP_LINE_FEED); } else { - List inlays = myEditor.getInlayModel().getAfterLineEndElementsForLogicalLine(iterator.getEndLogicalLine()); + List> inlays = myEditor.getInlayModel().getAfterLineEndElementsForLogicalLine(iterator.getEndLogicalLine()); if (!inlays.isEmpty()) { x += myView.getPlainSpaceWidth(); - for (Inlay inlay : inlays) { + for (Inlay inlay : inlays) { x += inlay.getWidthInPixels(); } } diff --git a/platform/platform-impl/src/com/intellij/ui/KeyStrokeAdapter.java b/platform/platform-impl/src/com/intellij/ui/KeyStrokeAdapter.java index 250341937ce2..4d4de48134df 100644 --- a/platform/platform-impl/src/com/intellij/ui/KeyStrokeAdapter.java +++ b/platform/platform-impl/src/com/intellij/ui/KeyStrokeAdapter.java @@ -5,6 +5,7 @@ import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.registry.Registry; import com.intellij.openapi.util.text.StringUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import javax.swing.*; import java.awt.event.InputEvent; @@ -298,7 +299,7 @@ public class KeyStrokeAdapter implements KeyListener { private static final class LazyVirtualKeys { private static final Map myNameToCode = new HashMap<>(); - private static final Map myCodeToName = new HashMap<>(); + private static final Int2ObjectOpenHashMap myCodeToName = new Int2ObjectOpenHashMap<>(); static { try { diff --git a/platform/statistics/intellij.platform.statistics.iml b/platform/statistics/intellij.platform.statistics.iml index 61028c0e98d5..1be70621bb4e 100644 --- a/platform/statistics/intellij.platform.statistics.iml +++ b/platform/statistics/intellij.platform.statistics.iml @@ -17,5 +17,6 @@ + \ No newline at end of file diff --git a/platform/statistics/src/com/intellij/internal/statistic/eventLog/ShortcutDataProvider.java b/platform/statistics/src/com/intellij/internal/statistic/eventLog/ShortcutDataProvider.java index b521d049c8ab..e18c8ffea9d5 100644 --- a/platform/statistics/src/com/intellij/internal/statistic/eventLog/ShortcutDataProvider.java +++ b/platform/statistics/src/com/intellij/internal/statistic/eventLog/ShortcutDataProvider.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.internal.statistic.eventLog; import com.intellij.openapi.actionSystem.ActionPlaces; @@ -6,6 +6,7 @@ import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.KeyboardShortcut; import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.Nullable; import javax.swing.*; @@ -13,15 +14,12 @@ import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.util.ArrayList; -import java.util.HashMap; import java.util.List; -import java.util.Map; import java.util.stream.Collectors; import static java.awt.event.KeyEvent.*; -public class ShortcutDataProvider { - +public final class ShortcutDataProvider { @Nullable public static String getActionEventText(@Nullable AnActionEvent event) { return event != null ? getInputEventText(event.getInputEvent(), event.getPlace()) : null; @@ -139,7 +137,7 @@ public class ShortcutDataProvider { return StringUtil.join(pressed, "+"); } - private static final Map ourKeyCodes = new HashMap<>(); + private static final Int2ObjectOpenHashMap ourKeyCodes = new Int2ObjectOpenHashMap<>(); static { ourKeyCodes.put(VK_ENTER, "Enter"); diff --git a/platform/util/src/com/intellij/util/containers/BidirectionalMap.java b/platform/util/src/com/intellij/util/containers/BidirectionalMap.java index 4bb7f9b8ef99..e39926e5f511 100644 --- a/platform/util/src/com/intellij/util/containers/BidirectionalMap.java +++ b/platform/util/src/com/intellij/util/containers/BidirectionalMap.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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.util.containers; import com.intellij.util.SmartList; @@ -72,7 +58,7 @@ public class BidirectionalMap implements Map{ @Override public boolean containsKey(Object key){ return myKeyToValueMap.containsKey(key); - } + } @Override @SuppressWarnings("SuspiciousMethodCalls") diff --git a/platform/util/src/com/intellij/util/containers/IntArrayList.java b/platform/util/src/com/intellij/util/containers/IntArrayList.java index 0083f7260f00..b032e4e9f890 100644 --- a/platform/util/src/com/intellij/util/containers/IntArrayList.java +++ b/platform/util/src/com/intellij/util/containers/IntArrayList.java @@ -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.util.containers; import com.intellij.util.ArrayUtil; @@ -6,6 +6,10 @@ import org.jetbrains.annotations.NotNull; import java.util.Arrays; +/** + * @deprecated Use {@link it.unimi.dsi.fastutil.ints.IntArrayList} + */ +@Deprecated public final class IntArrayList implements Cloneable { private int[] myData; private int mySize; diff --git a/platform/vcs-api/intellij.platform.vcs.iml b/platform/vcs-api/intellij.platform.vcs.iml index 9db64295bbcd..99fd19a5806d 100644 --- a/platform/vcs-api/intellij.platform.vcs.iml +++ b/platform/vcs-api/intellij.platform.vcs.iml @@ -17,5 +17,6 @@ + \ No newline at end of file diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/VcsRareLineAnnotationData.java b/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/VcsRareLineAnnotationData.java index 4b07e50115d1..d9105853aec3 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/VcsRareLineAnnotationData.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/annotate/VcsRareLineAnnotationData.java @@ -1,35 +1,18 @@ -/* - * Copyright 2000-2011 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.openapi.vcs.annotate; import com.intellij.openapi.vcs.history.VcsRevisionNumber; - -import java.util.HashMap; -import java.util.Map; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; /** * @author irengrig */ -public class VcsRareLineAnnotationData implements VcsLineAnnotationData { - private final Map myMap; +public final class VcsRareLineAnnotationData implements VcsLineAnnotationData { + private final Int2ObjectOpenHashMap myMap = new Int2ObjectOpenHashMap<>(); private final int mySize; - public VcsRareLineAnnotationData(final int size) { + public VcsRareLineAnnotationData(int size) { mySize = size; - myMap = new HashMap<>(); } @Override diff --git a/platform/vcs-impl/intellij.platform.vcs.impl.iml b/platform/vcs-impl/intellij.platform.vcs.impl.iml index b0aeea340ba3..eb6723bbb9a8 100644 --- a/platform/vcs-impl/intellij.platform.vcs.impl.iml +++ b/platform/vcs-impl/intellij.platform.vcs.impl.iml @@ -28,5 +28,6 @@ + \ No newline at end of file diff --git a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/apply/GenericPatchApplier.java b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/apply/GenericPatchApplier.java index c5267017d98f..73af2a90443c 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/apply/GenericPatchApplier.java +++ b/platform/vcs-impl/src/com/intellij/openapi/diff/impl/patch/apply/GenericPatchApplier.java @@ -1,7 +1,6 @@ // 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.diff.impl.patch.apply; -import com.intellij.diff.util.IntPair; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.diff.impl.patch.ApplyPatchStatus; import com.intellij.openapi.diff.impl.patch.PatchHunk; @@ -15,6 +14,7 @@ import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.changes.patch.AppliedTextPatch; import com.intellij.util.BeforeAfter; import com.intellij.util.Consumer; +import com.intellij.util.IntPair; import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -629,9 +629,9 @@ public class GenericPatchApplier { AppliedTextPatch.HunkStatus hunkStatus) { if (hunk != null) { // +1 to the end because end range is always not included -> [i;j); except add modification; - int newStart = lineWithPartContextApplied.getStartOffset() + contextRangeShift.val1; + int newStart = lineWithPartContextApplied.getStartOffset() + contextRangeShift.first; int newEnd = hunk.isInsertion() && hunkStatus != AppliedTextPatch.HunkStatus.ALREADY_APPLIED - ? newStart : lineWithPartContextApplied.getEndOffset() + 1 - contextRangeShift.val2; + ? newStart : lineWithPartContextApplied.getEndOffset() + 1 - contextRangeShift.second; myAppliedInfo.add(new AppliedTextPatch.AppliedSplitPatchHunk(hunk, newStart, newEnd, hunkStatus)); } } @@ -659,7 +659,7 @@ public class GenericPatchApplier { } } - private static class Point { + private static final class Point { private final int myDistance; private final int myContextDistance; private final int myCommon; @@ -694,7 +694,7 @@ public class GenericPatchApplier { } } - private class SequentialStepsChecker { + private final class SequentialStepsChecker { private int myDistance; // in the end, will be [excluding] end of changing interval private int myIdx; @@ -758,7 +758,7 @@ public class GenericPatchApplier { } } - private static class FirstLineDescriptor { + private static final class FirstLineDescriptor { private final String myLine; private final int myOffset; private final int myStepNumber; @@ -794,7 +794,7 @@ public class GenericPatchApplier { } } - private static class ExactMatchSolver extends MismatchSolver { + private static final class ExactMatchSolver extends MismatchSolver { private ExactMatchSolver(final SplitHunk hunk) { super(false); final List>> steps = hunk.getPatchSteps(); @@ -860,7 +860,7 @@ public class GenericPatchApplier { new WalkingIterator(line, originalStart, maxWalkFromBinding, false)); } - private class WalkingIterator implements Iterator { + private final class WalkingIterator implements Iterator { private final String myLine; // true = down private final boolean myDirection; @@ -973,7 +973,7 @@ public class GenericPatchApplier { } // will not find consider fragments that intersect - private class FragmentMatcher { + private final class FragmentMatcher { private final int myIdx; private int myOffsetIdxInHunk; // if we set index in hunk != 0, then we will check only one side diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/DateChangeListGroupingStrategy.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/DateChangeListGroupingStrategy.java index e60a75815031..aac4e95876de 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/DateChangeListGroupingStrategy.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/committed/DateChangeListGroupingStrategy.java @@ -1,17 +1,21 @@ -// 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.openapi.vcs.changes.committed; import com.intellij.openapi.vcs.VcsBundle; import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NonNls; import java.text.SimpleDateFormat; -import java.util.*; +import java.util.Calendar; +import java.util.Comparator; +import java.util.Date; +import java.util.Locale; /** * @author irengrig */ -public class DateChangeListGroupingStrategy implements ChangeListGroupingStrategy { +public final class DateChangeListGroupingStrategy implements ChangeListGroupingStrategy { @NonNls private final SimpleDateFormat myMonthYearFormat = new SimpleDateFormat("MMMM yyyy", Locale.ENGLISH); private long myTimeToRecalculateAfter; private Calendar myCurrentCalendar; @@ -73,36 +77,34 @@ public class DateChangeListGroupingStrategy implements ChangeListGroupingStrateg return CommittedChangeListByDateComparator.DESCENDING; } - private static class MonthsCache { - @NonNls private final SimpleDateFormat myMonthFormat = new SimpleDateFormat("MMMM", Locale.ENGLISH); - private final Map myCache; + private static final class MonthsCache { + private final Int2ObjectOpenHashMap myCache = new Int2ObjectOpenHashMap<>(12); - private MonthsCache(final Calendar calendarForInit) { - myCache = new HashMap<>(); + private MonthsCache(Calendar calendarForInit) { + SimpleDateFormat monthFormat = new SimpleDateFormat("MMMM", Locale.ENGLISH); for (int i = 0; i < 12; i++) { calendarForInit.set(Calendar.MONTH, i); - myCache.put(i, myMonthFormat.format(calendarForInit.getTime())); + myCache.put(i, monthFormat.format(calendarForInit.getTime())); } } - public String get(final int month) { + public String get(int month) { return myCache.get(month); } } - private static class WeekDayFormatCache { - @NonNls private final SimpleDateFormat myWeekdayFormat = new SimpleDateFormat("EEEE", Locale.ENGLISH); - private final Map myCache; + private static final class WeekDayFormatCache { + private final Int2ObjectOpenHashMap myCache = new Int2ObjectOpenHashMap<>(7); private WeekDayFormatCache(final Calendar calendarForInit) { - myCache = new HashMap<>(); + SimpleDateFormat weekdayFormat = new SimpleDateFormat("EEEE", Locale.ENGLISH); for (int i = 1; i < 8; i++) { calendarForInit.set(Calendar.DAY_OF_WEEK, i); - myCache.put(i, myWeekdayFormat.format(calendarForInit.getTime())); + myCache.put(i, weekdayFormat.format(calendarForInit.getTime())); } } - public String get(final int dayOfWeek) { + public String get(int dayOfWeek) { return myCache.get(dayOfWeek); } } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/issueLinks/IssueLinkHtmlRenderer.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/issueLinks/IssueLinkHtmlRenderer.java index 386e56a0be4c..e5326a1a0f88 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/issueLinks/IssueLinkHtmlRenderer.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/issueLinks/IssueLinkHtmlRenderer.java @@ -1,18 +1,4 @@ -/* - * Copyright 2000-2009 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.openapi.vcs.changes.issueLinks; import com.intellij.openapi.project.Project; @@ -31,7 +17,7 @@ import java.util.List; /** * @author yole */ -public class IssueLinkHtmlRenderer { +public final class IssueLinkHtmlRenderer { private IssueLinkHtmlRenderer() { } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java index 37ea2c6f3d7e..d28a4aca6f28 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/history/impl/VcsSelectionHistoryDialog.java @@ -13,7 +13,6 @@ import com.intellij.diff.requests.MessageDiffRequest; import com.intellij.diff.requests.NoDiffRequest; import com.intellij.diff.requests.SimpleDiffRequest; import com.intellij.diff.util.DiffUserDataKeysEx; -import com.intellij.diff.util.IntPair; import com.intellij.openapi.Disposable; import com.intellij.openapi.actionSystem.*; import com.intellij.openapi.application.ModalityState; @@ -37,6 +36,7 @@ import com.intellij.ui.components.panels.Wrapper; import com.intellij.ui.table.TableView; import com.intellij.util.ArrayUtil; import com.intellij.util.Consumer; +import com.intellij.util.IntPair; import com.intellij.util.containers.ContainerUtil; import com.intellij.util.ui.AnimatedIcon; import com.intellij.util.ui.*; @@ -55,6 +55,7 @@ import java.awt.event.ActionListener; import java.io.IOException; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import static com.intellij.util.ObjectUtils.notNull; @@ -161,7 +162,7 @@ public final class VcsSelectionHistoryDialog extends FrameWrapper implements Dat final VcsFileRevision revision; if (myList.getSelectedRowCount() == 1 && !myList.isEmpty()) { revision = myList.getItems().get(myList.getSelectedRow()); - String message = IssueLinkHtmlRenderer.formatTextIntoHtml(myProject, revision.getCommitMessage()); + String message = IssueLinkHtmlRenderer.formatTextIntoHtml(myProject, Objects.requireNonNull(revision.getCommitMessage())); myComments.setText(message); myComments.setCaretPosition(0); } @@ -271,7 +272,7 @@ public final class VcsSelectionHistoryDialog extends FrameWrapper implements Dat } IntPair range = getSelectedRevisionsRange(data); - List oldSelection = data.getRevisions().subList(range.val1, range.val2); + List oldSelection = data.getRevisions().subList(range.first, range.second); myListModel.setItems(newItems); @@ -374,8 +375,8 @@ public final class VcsSelectionHistoryDialog extends FrameWrapper implements Dat } IntPair range = getSelectedRevisionsRange(blockData); - int revIndex1 = range.val2; - int revIndex2 = range.val1; + int revIndex1 = range.second; + int revIndex2 = range.first; if (revIndex1 == count && revIndex2 == count) { myDiffPanel.setRequest(NoDiffRequest.INSTANCE); @@ -691,12 +692,12 @@ public final class VcsSelectionHistoryDialog extends FrameWrapper implements Dat IntPair range = dialog.getSelectedRevisionsRange(blockData); List revisions = blockData.getRevisions(); - VcsFileRevision beforeRevision = range.val2 < revisions.size() ? revisions.get(range.val2) : VcsFileRevision.NULL; - VcsFileRevision afterRevision = revisions.get(range.val1); + VcsFileRevision beforeRevision = range.second < revisions.size() ? revisions.get(range.second) : VcsFileRevision.NULL; + VcsFileRevision afterRevision = revisions.get(range.first); FilePath filePath = VcsUtil.getFilePath(dialog.myFile); - if (range.val2 - range.val1 > 1) { + if (range.second - range.first > 1) { dialog.getDiffHandler().showDiffForTwo(dialog.myProject, filePath, beforeRevision, afterRevision); } else { diff --git a/platform/vcs-impl/src/com/intellij/unscramble/AnnotateStackTraceAction.java b/platform/vcs-impl/src/com/intellij/unscramble/AnnotateStackTraceAction.java index 40f330c29870..709f763d9b36 100644 --- a/platform/vcs-impl/src/com/intellij/unscramble/AnnotateStackTraceAction.java +++ b/platform/vcs-impl/src/com/intellij/unscramble/AnnotateStackTraceAction.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.unscramble; import com.intellij.execution.filters.FileHyperlinkInfo; @@ -37,13 +37,17 @@ import com.intellij.openapi.vcs.history.VcsHistorySession; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.containers.MultiMap; import com.intellij.util.text.DateFormatUtil; import com.intellij.util.ui.update.MergingUpdateQueue; import com.intellij.util.ui.update.Update; import com.intellij.vcs.history.VcsHistoryProviderEx; import com.intellij.vcsUtil.VcsUtil; import com.intellij.xml.util.XmlStringUtil; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntListIterator; +import it.unimi.dsi.fastutil.objects.Object2ObjectMaps; +import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; import org.jetbrains.annotations.CalledInAwt; import org.jetbrains.annotations.CalledWithReadLock; import org.jetbrains.annotations.NotNull; @@ -93,8 +97,8 @@ public class AnnotateStackTraceAction extends DumbAwareAction { @Override public void run(@NotNull ProgressIndicator indicator) { - MultiMap files2lines = new MultiMap<>(); - Map revisions = new HashMap<>(); + Object2ObjectOpenHashMap files2lines = new Object2ObjectOpenHashMap<>(); + Int2ObjectOpenHashMap revisions = new Int2ObjectOpenHashMap<>(); ApplicationManager.getApplication().runReadAction(() -> { for (int line = 0; line < editor.getDocument().getLineCount(); line++) { @@ -102,21 +106,21 @@ public class AnnotateStackTraceAction extends DumbAwareAction { VirtualFile file = getHyperlinkVirtualFile(hyperlinks.findAllHyperlinksOnLine(line)); if (file == null) continue; - files2lines.putValue(file, line); + files2lines.computeIfAbsent(file, __ -> new IntArrayList()).add(line); } }); - files2lines.entrySet().forEach(entry -> { - indicator.checkCanceled(); + for (Map.Entry entry : Object2ObjectMaps.fastIterable(files2lines)) { VirtualFile file = entry.getKey(); - Collection lines = entry.getValue(); - + IntArrayList value = entry.getValue(); + indicator.checkCanceled(); LastRevision revision = getLastRevision(file); - if (revision == null) return; - + if (revision == null) { + continue; + } synchronized (LOCK) { - for (Integer line : lines) { - revisions.put(line, revision); + for (IntListIterator iterator = value.iterator(); iterator.hasNext(); ) { + revisions.put(iterator.nextInt(), revision); } } @@ -126,7 +130,7 @@ public class AnnotateStackTraceAction extends DumbAwareAction { updateGutter(indicator, revisions); } }); - }); + } // myUpdateQueue can be disposed before the last revisions are passed to the gutter ApplicationManager.getApplication().invokeLater(() -> updateGutter(indicator, revisions)); diff --git a/plugins/svn4idea/intellij.vcs.svn.iml b/plugins/svn4idea/intellij.vcs.svn.iml index c2c7b6be64d7..107b6ff4d2c1 100644 --- a/plugins/svn4idea/intellij.vcs.svn.iml +++ b/plugins/svn4idea/intellij.vcs.svn.iml @@ -38,5 +38,6 @@ + \ No newline at end of file diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/annotate/BaseSvnFileAnnotation.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/annotate/BaseSvnFileAnnotation.java index 4dc7782ce179..34357588611e 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/annotate/BaseSvnFileAnnotation.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/annotate/BaseSvnFileAnnotation.java @@ -7,6 +7,7 @@ import com.intellij.openapi.vcs.history.VcsFileRevision; import com.intellij.openapi.vcs.history.VcsRevisionNumber; import com.intellij.xml.util.XmlStringUtil; import git4idea.annotate.AnnotationTooltipBuilder; +import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.idea.svn.SvnBundle; @@ -257,15 +258,15 @@ public abstract class BaseSvnFileAnnotation extends FileAnnotation { protected abstract void showAllAffectedPaths(SvnRevisionNumber number); - private static class MyPartiallyCreatedInfos { + private static final class MyPartiallyCreatedInfos { private boolean myShowMergeSource; - private final Map myMappedLineInfo; - private final Map myMergeSourceInfos; + private final Int2ObjectOpenHashMap myMappedLineInfo; + private final Int2ObjectOpenHashMap myMergeSourceInfos; private int myMaxIdx; private MyPartiallyCreatedInfos() { - myMergeSourceInfos = new HashMap<>(); - myMappedLineInfo = new HashMap<>(); + myMergeSourceInfos = new Int2ObjectOpenHashMap<>(); + myMappedLineInfo = new Int2ObjectOpenHashMap<>(); myMaxIdx = 0; } @@ -279,7 +280,7 @@ public abstract class BaseSvnFileAnnotation extends FileAnnotation { void appendNumberedLineInfo(final int lineNumber, @NotNull CommitInfo info, @Nullable CommitInfo mergeInfo) { if (myMappedLineInfo.get(lineNumber) != null) return; - myMaxIdx = (myMaxIdx < lineNumber) ? lineNumber : myMaxIdx; + myMaxIdx = Math.max(myMaxIdx, lineNumber); myMappedLineInfo.put(lineNumber, info); if (mergeInfo != null) { myMergeSourceInfos.put(lineNumber, mergeInfo); diff --git a/plugins/yaml/intellij.yaml.iml b/plugins/yaml/intellij.yaml.iml index d81c1471f86a..a356803a4702 100644 --- a/plugins/yaml/intellij.yaml.iml +++ b/plugins/yaml/intellij.yaml.iml @@ -19,5 +19,6 @@ + \ No newline at end of file diff --git a/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLQuotedTextImpl.java b/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLQuotedTextImpl.java index 4df021ecbd04..cd2cf7511a89 100644 --- a/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLQuotedTextImpl.java +++ b/plugins/yaml/src/org/jetbrains/yaml/psi/impl/YAMLQuotedTextImpl.java @@ -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.yaml.psi.impl; import com.intellij.lang.ASTNode; @@ -8,6 +8,7 @@ import com.intellij.openapi.util.TextRange; import com.intellij.openapi.util.text.StringUtil; import com.intellij.psi.PsiElementVisitor; import com.intellij.util.ObjectUtils; +import it.unimi.dsi.fastutil.ints.Int2IntOpenHashMap; import org.jetbrains.annotations.NotNull; import org.jetbrains.yaml.YAMLTokenTypes; import org.jetbrains.yaml.YAMLUtil; @@ -15,9 +16,11 @@ import org.jetbrains.yaml.lexer.YAMLGrammarCharUtil; import org.jetbrains.yaml.psi.YAMLQuotedText; import org.jetbrains.yaml.psi.YamlPsiElementVisitor; -import java.util.*; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; -public class YAMLQuotedTextImpl extends YAMLScalarImpl implements YAMLQuotedText { +public final class YAMLQuotedTextImpl extends YAMLScalarImpl implements YAMLQuotedText { private final boolean myIsSingleQuoted; public YAMLQuotedTextImpl(@NotNull ASTNode node) { @@ -196,7 +199,7 @@ public class YAMLQuotedTextImpl extends YAMLScalarImpl implements YAMLQuotedText return "YAML quoted text"; } - private static class Escaper { + private static final class Escaper { private static final int[][] ONE_LETTER_CONVERSIONS = new int[][] { {'0', 0}, {'a', 7}, @@ -218,29 +221,13 @@ public class YAMLQuotedTextImpl extends YAMLScalarImpl implements YAMLQuotedText {'P', 8233}, }; - private static final NotNullLazyValue> ESC_TO_CODE = new NotNullLazyValue>() { - @NotNull - @Override - protected Map compute() { - final HashMap map = new HashMap<>(ONE_LETTER_CONVERSIONS.length); - for (int[] conversion : ONE_LETTER_CONVERSIONS) { - map.put(conversion[0], conversion[1]); - } - return map; + private static final NotNullLazyValue ESC_TO_CODE = NotNullLazyValue.createValue(() -> { + Int2IntOpenHashMap map = new Int2IntOpenHashMap(ONE_LETTER_CONVERSIONS.length); + for (int[] conversion : ONE_LETTER_CONVERSIONS) { + map.put(conversion[0], conversion[1]); } - }; - - private static final NotNullLazyValue> CODE_TO_ESC = new NotNullLazyValue>() { - @NotNull - @Override - protected Map compute() { - final HashMap map = new HashMap<>(ONE_LETTER_CONVERSIONS.length); - for (int[] conversion : ONE_LETTER_CONVERSIONS) { - map.put(conversion[1], conversion[2]); - } - return map; - } - }; + return map; + }); static int findEscapementLength(@NotNull CharSequence text, int pos) { if (pos + 1 >= text.length() || text.charAt(pos) != '\\') { @@ -269,11 +256,11 @@ public class YAMLQuotedTextImpl extends YAMLScalarImpl implements YAMLQuotedText return Integer.parseInt(s.toString(), 16); } catch (NumberFormatException e) { - return (int)'?'; + return '?'; } } else { - final Integer result = ESC_TO_CODE.getValue().get((int)text.charAt(pos + 1)); + final Integer result = ESC_TO_CODE.getValue().get(text.charAt(pos + 1)); return ObjectUtils.notNull(result, (int)text.charAt(pos + 1)); } } diff --git a/xml/xml-psi-impl/intellij.xml.psi.impl.iml b/xml/xml-psi-impl/intellij.xml.psi.impl.iml index 5458e098d55d..d0e0ad056d4a 100644 --- a/xml/xml-psi-impl/intellij.xml.psi.impl.iml +++ b/xml/xml-psi-impl/intellij.xml.psi.impl.iml @@ -22,5 +22,6 @@ + \ No newline at end of file diff --git a/xml/xml-psi-impl/src/com/intellij/xml/util/ColorIconCache.java b/xml/xml-psi-impl/src/com/intellij/xml/util/ColorIconCache.java index b4f1f8b01d7a..1a9ac65e271d 100644 --- a/xml/xml-psi-impl/src/com/intellij/xml/util/ColorIconCache.java +++ b/xml/xml-psi-impl/src/com/intellij/xml/util/ColorIconCache.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.xml.util; import com.intellij.util.containers.SoftFactoryMap; @@ -8,18 +8,15 @@ import org.jetbrains.annotations.NotNull; import javax.swing.*; import java.awt.*; import java.util.Arrays; -import java.util.Map; import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; -/** - * @author spleaner - */ -public class ColorIconCache { +public final class ColorIconCache { private static final ColorIconCache INSTANCE = new ColorIconCache(); - private static final SoftFactoryMap> ourCache = new SoftFactoryMap>() { + private static final SoftFactoryMap> ourCache = new SoftFactoryMap>() { @Override - protected Map create(Color key) { + protected ConcurrentMap create(Color key) { return new ConcurrentHashMap<>(); } };