Don't pass entire file content to file type detectors (avoid performance issues such as https://youtrack.jetbrains.com/issue/IDEA-286489)

GitOrigin-RevId: 73f666ed8e678c818dacfc62518ed911e7afe0dc
This commit is contained in:
Dmitry Jemerov
2022-01-19 14:06:21 +01:00
committed by intellij-monorepo-bot
parent 7a559d8394
commit 029964c1b6

View File

@@ -608,8 +608,8 @@ final class FileTypeDetectionService implements Disposable {
@NotNull
private ByteArraySequence getFirstBytes(@NotNull VirtualFile file, byte @Nullable [] content) throws IOException {
int bufferLength = getDetectFileBufferSize(file);
if (content == null) {
int bufferLength = getDetectFileBufferSize(file);
try {
return ProgressManager.getInstance().isInNonCancelableSection() || ApplicationManager.getApplication().isWriteThread()
? readFirstBytesFromFile(file, bufferLength)
@@ -620,7 +620,7 @@ final class FileTypeDetectionService implements Disposable {
}
}
else {
return content.length != 0 ? new ByteArraySequence(content) : ByteArraySequence.EMPTY;
return content.length != 0 ? new ByteArraySequence(content, 0, Math.min(content.length, bufferLength)) : ByteArraySequence.EMPTY;
}
}