mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[performance for 143] make somewhat less intrusive but more public way of reusing loaded file content
This commit is contained in:
@@ -16,7 +16,6 @@
|
||||
package com.intellij.psi.impl.compiled;
|
||||
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.compiled.ClassFileDecompilers;
|
||||
import com.intellij.psi.stubs.BinaryFileStubBuilder;
|
||||
@@ -40,7 +39,6 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.psi.impl.compiled.ClassFileStubBuilder");
|
||||
|
||||
public static final int STUB_VERSION = 12;
|
||||
public static final Key<byte[]> ourCompiledClassContentHintKey = Key.create("compiled.class.content.hint");
|
||||
|
||||
@Override
|
||||
public boolean acceptsFile(@NotNull VirtualFile file) {
|
||||
@@ -53,7 +51,7 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
|
||||
byte[] content = fileContent.getContent();
|
||||
|
||||
try {
|
||||
file.putUserData(ourCompiledClassContentHintKey, content);
|
||||
file.setForcedContentHint(content);
|
||||
ClassFileDecompilers.Decompiler decompiler = ClassFileDecompilers.find(file);
|
||||
if (decompiler instanceof Full) {
|
||||
return ((Full)decompiler).getStubBuilder().buildFileStub(fileContent);
|
||||
@@ -63,7 +61,7 @@ public class ClassFileStubBuilder implements BinaryFileStubBuilder {
|
||||
LOG.debug(e);
|
||||
}
|
||||
finally {
|
||||
file.putUserData(ourCompiledClassContentHintKey, null);
|
||||
file.setForcedContentHint(null);
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
@@ -750,4 +750,7 @@ public abstract class VirtualFile extends UserDataHolderBase implements Modifica
|
||||
public CharSequence getNameSequence() {
|
||||
return getName();
|
||||
}
|
||||
|
||||
public void setForcedContentHint(byte[] forcedContent) {
|
||||
}
|
||||
}
|
||||
|
||||
+20
-1
@@ -19,17 +19,20 @@
|
||||
*/
|
||||
package com.intellij.openapi.vfs.newvfs.impl;
|
||||
|
||||
import com.intellij.openapi.util.Key;
|
||||
import com.intellij.openapi.vfs.VfsUtilCore;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.NewVirtualFile;
|
||||
import com.intellij.openapi.vfs.newvfs.NewVirtualFileSystem;
|
||||
import com.intellij.util.LineSeparator;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.io.UnsyncByteArrayInputStream;
|
||||
import com.intellij.util.keyFMap.KeyFMap;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.DataInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
@@ -90,10 +93,24 @@ public class VirtualFileImpl extends VirtualFileSystemEntry {
|
||||
return false;
|
||||
}
|
||||
|
||||
private static final Key<byte[]> ourForcedContentKey = Key.create("forced.content.key");
|
||||
|
||||
@Override
|
||||
public void setForcedContentHint(byte[] forcedContent) {
|
||||
putUserData(ourForcedContentKey, forcedContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public InputStream getInputStream() throws IOException {
|
||||
return VfsUtilCore.inputStreamSkippingBOM(ourPersistence.getInputStream(this), this);
|
||||
final byte[] forcedContent = getUserData(ourForcedContentKey);
|
||||
|
||||
return VfsUtilCore.inputStreamSkippingBOM(
|
||||
forcedContent == null ?
|
||||
ourPersistence.getInputStream(this):
|
||||
new DataInputStream(new UnsyncByteArrayInputStream(forcedContent)),
|
||||
this
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -105,6 +122,8 @@ public class VirtualFileImpl extends VirtualFileSystemEntry {
|
||||
@NotNull
|
||||
@Override
|
||||
public byte[] contentsToByteArray(boolean cacheContent) throws IOException {
|
||||
final byte[] forcedContent = getUserData(ourForcedContentKey);
|
||||
if (forcedContent != null) return forcedContent;
|
||||
return ourPersistence.contentsToByteArray(this, cacheContent);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user