diff --git a/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index e1ae44bc05ec..8606b8b7953f 100644 --- a/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -842,6 +842,7 @@ public class FileBasedIndex implements ApplicationComponent { private void markDirty(final VirtualFileEvent event) { iterateIndexableFiles(event.getFile(), new Processor() { public boolean process(final VirtualFile file) { + FileContent fileContent = null; for (ID indexId : myIndices.keySet()) { if (getInputFilter(indexId).acceptInput(file)) { if (myNeedContentLoading.contains(indexId)) { @@ -849,7 +850,10 @@ public class FileBasedIndex implements ApplicationComponent { } else { try { - updateSingleIndex(indexId, file, new FileContent(file, (byte[])null), null); + if (fileContent == null) { + fileContent = new FileContent(file, (byte[])null); + } + updateSingleIndex(indexId, file, fileContent, null); } catch (StorageException e) { LOG.info(e); @@ -877,6 +881,7 @@ public class FileBasedIndex implements ApplicationComponent { if (SingleRootFileViewProvider.isTooLarge(file)) return; final List> affectedIndices = new ArrayList>(myIndices.size()); + FileContent fileContent = null; for (ID indexId : myIndices.keySet()) { if (shouldUpdateIndex(file, indexId)) { if (myNeedContentLoading.contains(indexId)) { @@ -885,7 +890,10 @@ public class FileBasedIndex implements ApplicationComponent { else { // invalidate it synchronously try { - updateSingleIndex(indexId, file, null, new FileContent(file, (byte[])null)); + if (fileContent == null) { + fileContent = new FileContent(file, (byte[])null); + } + updateSingleIndex(indexId, file, null, fileContent); } catch (StorageException e) { LOG.info(e); @@ -1061,10 +1069,14 @@ public class FileBasedIndex implements ApplicationComponent { break; } } + FileContent fileContent = null; for (ID indexId : mySkipContentLoading) { if (shouldIndexFile(file, indexId)) { try { - updateSingleIndex(indexId, file, new FileContent(file, (byte[])null), null); + if (fileContent == null) { + fileContent = new FileContent(file, (byte[])null); + } + updateSingleIndex(indexId, file, fileContent, null); } catch (StorageException e) { LOG.info(e); diff --git a/lang-impl/src/com/intellij/util/indexing/FileContent.java b/lang-impl/src/com/intellij/util/indexing/FileContent.java index 09fcfaccb9e1..84995d3304ed 100644 --- a/lang-impl/src/com/intellij/util/indexing/FileContent.java +++ b/lang-impl/src/com/intellij/util/indexing/FileContent.java @@ -1,6 +1,5 @@ package com.intellij.util.indexing; -import com.intellij.openapi.fileEditor.impl.LoadTextUtil; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.vfs.VirtualFile; @@ -16,6 +15,7 @@ public final class FileContent { private final VirtualFile myFile; private final String fileName; private final FileType myFileType; + private final Charset myCharset; private byte[] myContent; private CharSequence myContentAsText = null; @@ -44,6 +44,7 @@ public final class FileContent { fileName = file.getName(); myContent = content; myContentAsText = contentAsText; + myCharset = file.getCharset(); } public VirtualFile getFile() { @@ -54,12 +55,15 @@ public final class FileContent { return fileName; } + public Charset getCharset() { + return myCharset; + } + public byte[] getContent() { if (myContent == null) { if (myContentAsText != null) { try { - final Charset charset = myFile.getCharset(); - myContent = charset != null? myContentAsText.toString().getBytes(charset.name()) : myContentAsText.toString().getBytes(); + myContent = myCharset != null? myContentAsText.toString().getBytes(myCharset.name()) : myContentAsText.toString().getBytes(); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); @@ -75,7 +79,12 @@ public final class FileContent { } if (myContentAsText == null) { if (myContent != null) { - myContentAsText = LoadTextUtil.getTextByBinaryPresentation(myContent, myFile, false); + try { + myContentAsText = new String(myContent, myCharset.name()); + } + catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } } return myContentAsText;