From edf084acb281dd4b27205cd9853a322635cbdc7e Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 10 Sep 2024 08:13:05 +0200 Subject: [PATCH] reduce GC a little bit, don't use ContainerUtil GitOrigin-RevId: f05f5f0b4a381eed5fda4b5780c028de4afe4b5b --- .../ArtifactOutputToSourceMapping.java | 52 +++++++++++++------ 1 file changed, 35 insertions(+), 17 deletions(-) diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactOutputToSourceMapping.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactOutputToSourceMapping.java index 69a7adc5b8db..a4c2185e107b 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactOutputToSourceMapping.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/artifacts/ArtifactOutputToSourceMapping.java @@ -1,8 +1,6 @@ -// Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. +// Copyright 2000-2024 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package org.jetbrains.jps.incremental.artifacts; -import com.intellij.util.SmartList; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.io.DataExternalizer; import com.intellij.util.io.IOUtil; import org.jetbrains.annotations.NotNull; @@ -12,13 +10,16 @@ import org.jetbrains.jps.incremental.storage.AbstractStateStorage; import org.jetbrains.jps.incremental.storage.PathStringDescriptor; import java.io.*; -import java.util.Collections; +import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** - * Stores source paths for each output path. If a source file or an output file is located in a jar file the path to the jar file is stored. + * Stores source paths for each output path. + * If a source file or an output file is located in a jar file, the path to the jar file is stored. */ -public final class ArtifactOutputToSourceMapping extends AbstractStateStorage> { +public final class ArtifactOutputToSourceMapping + extends AbstractStateStorage> { private final PathRelativizerService myRelativizer; public ArtifactOutputToSourceMapping(File storePath, PathRelativizerService relativizer) throws IOException { @@ -28,16 +29,16 @@ public final class ArtifactOutputToSourceMapping extends AbstractStateStorage state) throws IOException { - super.update(normalizePath(path), state != null ? normalizePaths(state) : null); + super.update(normalizePath(path), state == null ? null : normalizePaths(state)); } @Override public void appendData(String path, List data) throws IOException { - super.appendData(normalizePath(path), data != null ? normalizePaths(data) : null); + super.appendData(normalizePath(path), data == null ? null : normalizePaths(data)); } public void appendData(String outputPath, int rootIndex, String sourcePath) throws IOException { - super.appendData(normalizePath(outputPath), Collections.singletonList(new SourcePathAndRootIndex(normalizePath(sourcePath), rootIndex))); + super.appendData(normalizePath(outputPath), List.of(new SourcePathAndRootIndex(normalizePath(sourcePath), rootIndex))); } @Override @@ -48,7 +49,21 @@ public final class ArtifactOutputToSourceMapping extends AbstractStateStorage getState(String path) throws IOException { List list = super.getState(normalizePath(path)); - return list != null ? ContainerUtil.map(list, it -> new SourcePathAndRootIndex(myRelativizer.toFull(it.myPath), it.myRootIndex)) : null; + if (list == null) { + return null; + } + else { + if (list.isEmpty()) { + return List.of(); + } + + SourcePathAndRootIndex[] result = new SourcePathAndRootIndex[list.size()]; + for (int i = 0; i < list.size(); i++) { + ArtifactOutputToSourceMapping.SourcePathAndRootIndex t = list.get(i); + result[i] = new SourcePathAndRootIndex(myRelativizer.toFull(t.myPath), t.myRootIndex); + } + return Arrays.asList(result); + } } private String normalizePath(@NotNull String path) { @@ -56,9 +71,12 @@ public final class ArtifactOutputToSourceMapping extends AbstractStateStorage normalizePaths(@NotNull List state) { - List normalizePathList = new SmartList<>(); - state.forEach(it -> normalizePathList.add(new SourcePathAndRootIndex(normalizePath(it.myPath), it.myRootIndex))); - return normalizePathList; + SourcePathAndRootIndex[] result = new SourcePathAndRootIndex[state.size()]; + for (int i = 0, size = state.size(); i < size; i++) { + SourcePathAndRootIndex it = state.get(i); + result[i] = new SourcePathAndRootIndex(normalizePath(it.myPath), it.myRootIndex); + } + return Arrays.asList(result); } public static final class SourcePathAndRootIndex { @@ -90,11 +108,11 @@ public final class ArtifactOutputToSourceMapping extends AbstractStateStorage read(@NotNull DataInput in) throws IOException { - List result = new SmartList<>(); - final DataInputStream stream = (DataInputStream)in; + List result = new ArrayList<>(); + DataInputStream stream = (DataInputStream)in; while (stream.available() > 0) { - final String path = IOUtil.readUTF(stream); - final int index = stream.readInt(); + String path = IOUtil.readUTF(stream); + int index = stream.readInt(); result.add(new SourcePathAndRootIndex(path, index)); } return result;