mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
calc hash from content once we have bytes available, don't delay its processing until we have only chars
This commit is contained in:
@@ -45,6 +45,7 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon
|
||||
private byte[] myContent;
|
||||
private CharSequence myContentAsText;
|
||||
private final long myStamp;
|
||||
private final int myHashId;
|
||||
|
||||
@Override
|
||||
public Project getProject() {
|
||||
@@ -90,26 +91,32 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon
|
||||
}
|
||||
|
||||
public FileContentImpl(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText, final Charset charset) {
|
||||
this(file, contentAsText, null, charset, -1);
|
||||
this(file, contentAsText, null, charset, -1, -1);
|
||||
}
|
||||
|
||||
public FileContentImpl(@NotNull final VirtualFile file, @NotNull final CharSequence contentAsText, final Charset charset, long documentStamp) {
|
||||
this(file, contentAsText, null, charset, documentStamp);
|
||||
this(file, contentAsText, null, charset, documentStamp, -1);
|
||||
}
|
||||
|
||||
public FileContentImpl(@NotNull final VirtualFile file, @NotNull final byte[] content) {
|
||||
this(file, null, content, LoadTextUtil.detectCharsetAndSetBOM(file, content), -1);
|
||||
this(file, content, -1);
|
||||
}
|
||||
|
||||
public FileContentImpl(@NotNull final VirtualFile file, @NotNull final byte[] content, int hashId) {
|
||||
this(file, null, content, LoadTextUtil.detectCharsetAndSetBOM(file, content), -1, hashId);
|
||||
}
|
||||
|
||||
public FileContentImpl(@NotNull final VirtualFile file) {
|
||||
this(file, null, null, null, -1);
|
||||
this(file, null, null, null, -1, -1);
|
||||
}
|
||||
|
||||
private FileContentImpl(@NotNull VirtualFile file,
|
||||
CharSequence contentAsText,
|
||||
byte[] content,
|
||||
Charset charset,
|
||||
long stamp) {
|
||||
long stamp,
|
||||
int hashId
|
||||
) {
|
||||
myFile = file;
|
||||
myContentAsText = contentAsText;
|
||||
myContent = content;
|
||||
@@ -118,6 +125,7 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon
|
||||
// remember name explicitly because the file could be renamed afterwards
|
||||
myFileName = file.getName();
|
||||
myStamp = stamp;
|
||||
myHashId = hashId;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -209,4 +217,8 @@ public final class FileContentImpl extends UserDataHolderBase implements FileCon
|
||||
public String toString() {
|
||||
return myFileName;
|
||||
}
|
||||
|
||||
public int getHashId() {
|
||||
return myHashId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1698,7 +1698,8 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
myChangedFilesCollector.ensureAllInvalidateTasksCompleted();
|
||||
final VirtualFile file = content.getVirtualFile();
|
||||
|
||||
FileTypeManagerImpl.cacheFileType(file, file.getFileType());
|
||||
FileType fileType = file.getFileType();
|
||||
FileTypeManagerImpl.cacheFileType(file, fileType);
|
||||
|
||||
try {
|
||||
PsiFile psiFile = null;
|
||||
@@ -1711,13 +1712,16 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
if (shouldIndexFile(file, indexId)) {
|
||||
if (fc == null) {
|
||||
byte[] currentBytes;
|
||||
int hashId;
|
||||
try {
|
||||
currentBytes = content.getBytes();
|
||||
hashId = ContentHashesSupport.calcContentHashIdWithFileType(currentBytes, fileType);
|
||||
}
|
||||
catch (IOException e) {
|
||||
currentBytes = ArrayUtil.EMPTY_BYTE_ARRAY;
|
||||
hashId = -1;
|
||||
}
|
||||
fc = new FileContentImpl(file, currentBytes);
|
||||
fc = new FileContentImpl(file, currentBytes, hashId);
|
||||
if (project == null) {
|
||||
project = ProjectUtil.guessProjectForFile(file);
|
||||
}
|
||||
|
||||
@@ -317,8 +317,8 @@ public class MapReduceIndex<Key, Value, Input> implements UpdatableIndex<Key,Val
|
||||
|
||||
if (content instanceof FileContent) {
|
||||
FileContent fileContent = (FileContent)content;
|
||||
Integer previouslyCalculatedContentHashId = fileContent.getUserData(ourSavedContentHashIdKey);
|
||||
if (previouslyCalculatedContentHashId == null) {
|
||||
int previouslyCalculatedContentHashId = fileContent instanceof FileContentImpl ? ((FileContentImpl)fileContent).getHashId():-1;
|
||||
if (previouslyCalculatedContentHashId == -1) {
|
||||
previouslyCalculatedContentHashId = ContentHashesSupport.calcContentHashIdWithFileType(fileContent.getContent(), fileContent.getFileType());
|
||||
fileContent.putUserData(ourSavedContentHashIdKey, previouslyCalculatedContentHashId);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user