Revert "stubs: inline logic for data externalization if compression is disabled"
authorDmitry Batkovich <dmitry.batkovich@jetbrains.com>
Thu, 13 Aug 2020 07:34:36 +0000 (10:34 +0300)
committerintellij-monorepo-bot <intellij-monorepo-bot-no-reply@jetbrains.com>
Thu, 13 Aug 2020 07:40:06 +0000 (07:40 +0000)
This reverts commit 2d3967f3

GitOrigin-RevId: 369c36586e8b61083e4e925d4961d99181efc9bf

platform/core-impl/src/com/intellij/psi/stubs/IndexingStampInfo.java
platform/core-impl/src/com/intellij/psi/stubs/StubTreeLoader.java
platform/indexing-impl/src/com/intellij/psi/stubs/PrebuiltStubs.kt
platform/indexing-impl/src/com/intellij/psi/stubs/SerializedStubTree.java
platform/indexing-impl/src/com/intellij/psi/stubs/SerializedStubTreeDataExternalizer.java
platform/lang-impl/src/com/intellij/psi/stubs/StubTreeLoaderImpl.java
platform/lang-impl/src/com/intellij/psi/stubs/StubUpdatingIndex.java
tools/index-tools/src/org/jetbrains/index/stubs/StubsGenerator.kt

index d295691b3ca1872198e3c8cf68d44143da0c8589..074462edf025605549ad610c65e187e36dd7b4dc 100644 (file)
@@ -20,24 +20,15 @@ import com.intellij.openapi.fileEditor.FileDocumentManager;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiFile;
 import com.intellij.openapi.vfs.VirtualFile;
 import com.intellij.psi.PsiDocumentManager;
 import com.intellij.psi.PsiFile;
-import com.intellij.util.BitUtil;
-import com.intellij.util.io.DataInputOutputUtil;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
-import java.io.DataInputStream;
-import java.io.DataOutput;
-import java.io.IOException;
-
 /**
  * An informational object for debugging stub-mismatch related issues. Should be as small as possible since it's stored in files's attributes.
  *
  * @author peter
  */
 class IndexingStampInfo {
 /**
  * An informational object for debugging stub-mismatch related issues. Should be as small as possible since it's stored in files's attributes.
  *
  * @author peter
  */
 class IndexingStampInfo {
-  private static final byte IS_BINARY_MASK = 1;
-  private static final byte BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK = 1 << 1;
-
   final long indexingFileStamp;
   final long indexingByteLength;
   final int indexingCharLength;
   final long indexingFileStamp;
   final long indexingByteLength;
   final int indexingCharLength;
@@ -50,54 +41,13 @@ class IndexingStampInfo {
     this.isBinary = isBinary;
   }
 
     this.isBinary = isBinary;
   }
 
-  void save(@NotNull DataOutput stream) throws IOException {
-    DataInputOutputUtil.writeTIME(stream, indexingFileStamp);
-    DataInputOutputUtil.writeLONG(stream, indexingByteLength);
-
-    boolean lengthsAreTheSame = indexingCharLength == indexingByteLength;
-    byte flags = 0;
-    flags = BitUtil.set(flags, IS_BINARY_MASK, isBinary);
-    flags = BitUtil.set(flags, BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK, lengthsAreTheSame);
-    stream.writeByte(flags);
-
-    if (!lengthsAreTheSame && !isBinary) {
-      DataInputOutputUtil.writeINT(stream, indexingCharLength);
-    }
-  }
-
-  @Nullable
-  static IndexingStampInfo read(@Nullable DataInputStream stream) throws IOException {
-    if (stream == null || stream.available() <= 0) {
-      return null;
-    }
-    long stamp = DataInputOutputUtil.readTIME(stream);
-    long byteLength = DataInputOutputUtil.readLONG(stream);
-
-    byte flags = stream.readByte();
-    boolean isBinary = BitUtil.isSet(flags, IS_BINARY_MASK);
-    boolean readOnlyOneLength = BitUtil.isSet(flags, BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK);
-
-    int charLength;
-    if (isBinary) {
-      charLength = -1;
-    }
-    else if (readOnlyOneLength) {
-      charLength = (int)byteLength;
-    }
-    else {
-      charLength = DataInputOutputUtil.readINT(stream);
-    }
-    return new IndexingStampInfo(stamp, byteLength, charLength, isBinary);
-  }
-
-
   @Override
   public String toString() {
     return "indexing timestamp = " + indexingFileStamp + ", " +
            "binary = " + isBinary + ", byte size = " + indexingByteLength + ", char size = " + indexingCharLength;
   }
 
   @Override
   public String toString() {
     return "indexing timestamp = " + indexingFileStamp + ", " +
            "binary = " + isBinary + ", byte size = " + indexingByteLength + ", char size = " + indexingCharLength;
   }
 
-  boolean isUpToDate(@Nullable Document document, @NotNull VirtualFile file, @NotNull PsiFile psi) {
+  public boolean isUpToDate(@Nullable Document document, @NotNull VirtualFile file, @NotNull PsiFile psi) {
     if (document == null ||
         FileDocumentManager.getInstance().isDocumentUnsaved(document) ||
         !PsiDocumentManager.getInstance(psi.getProject()).isCommitted(document)) {
     if (document == null ||
         FileDocumentManager.getInstance().isDocumentUnsaved(document) ||
         !PsiDocumentManager.getInstance(psi.getProject()).isCommitted(document)) {
@@ -110,7 +60,7 @@ class IndexingStampInfo {
            contentLengthMatches(file.getLength(), document.getTextLength());
   }
 
            contentLengthMatches(file.getLength(), document.getTextLength());
   }
 
-  boolean contentLengthMatches(long byteContentLength, int charContentLength) {
+  public boolean contentLengthMatches(long byteContentLength, int charContentLength) {
     if (this.indexingCharLength >= 0 && charContentLength >= 0) {
       return this.indexingCharLength == charContentLength;
     }
     if (this.indexingCharLength >= 0 && charContentLength >= 0) {
       return this.indexingCharLength == charContentLength;
     }
index a9d312dcf625fe86aacc4f57d4c2ad6078562ce7..1e2f10d07207b1b374789e0e03211d2c8be356ed 100644 (file)
@@ -46,7 +46,7 @@ public abstract class StubTreeLoader {
   }
 
   @Nullable
   }
 
   @Nullable
-  protected IndexingStampInfo getIndexingStampInfoFromAttributes(@NotNull VirtualFile file) {
+  protected IndexingStampInfo getIndexingStampInfo(@NotNull VirtualFile file) {
     return null;
   }
 
     return null;
   }
 
@@ -58,7 +58,7 @@ public abstract class StubTreeLoader {
     StubTree stubTreeFromIndex = (StubTree)readFromVFile(psiFile.getProject(), file);
     boolean compiled = psiFile instanceof PsiCompiledElement;
     Document document = compiled ? null : FileDocumentManager.getInstance().getDocument(file);
     StubTree stubTreeFromIndex = (StubTree)readFromVFile(psiFile.getProject(), file);
     boolean compiled = psiFile instanceof PsiCompiledElement;
     Document document = compiled ? null : FileDocumentManager.getInstance().getDocument(file);
-    IndexingStampInfo indexingStampInfo = getIndexingStampInfoFromAttributes(file);
+    IndexingStampInfo indexingStampInfo = getIndexingStampInfo(file);
     boolean upToDate = indexingStampInfo != null && indexingStampInfo.isUpToDate(document, file, psiFile);
 
     boolean canBePrebuilt = isPrebuilt(psiFile.getVirtualFile());
     boolean upToDate = indexingStampInfo != null && indexingStampInfo.isUpToDate(document, file, psiFile);
 
     boolean canBePrebuilt = isPrebuilt(psiFile.getVirtualFile());
index 0dd70c95947382edd5e420cf84f141eb43b750e9..f1e3b76932dabda020d04ded845a0572ac25a28d 100644 (file)
@@ -64,8 +64,7 @@ open class HashCodeExternalizers : DataExternalizer<HashCode> {
 }
 
 class GeneratingFullStubExternalizer : SerializedStubTreeDataExternalizer(SerializationManagerEx.getInstanceEx(),
 }
 
 class GeneratingFullStubExternalizer : SerializedStubTreeDataExternalizer(SerializationManagerEx.getInstanceEx(),
-                                                                          StubForwardIndexExternalizer.createFileLocalExternalizer(),
-                                                                          false)
+                                                                          StubForwardIndexExternalizer.createFileLocalExternalizer())
 
 abstract class PrebuiltStubsProviderBase : PrebuiltIndexProvider<SerializedStubTree>(), PrebuiltStubsProvider {
   private lateinit var mySerializationManager: SerializationManagerImpl
 
 abstract class PrebuiltStubsProviderBase : PrebuiltIndexProvider<SerializedStubTree>(), PrebuiltStubsProvider {
   private lateinit var mySerializationManager: SerializationManagerImpl
@@ -74,7 +73,7 @@ abstract class PrebuiltStubsProviderBase : PrebuiltIndexProvider<SerializedStubT
 
   override val indexName: String get() = SDK_STUBS_STORAGE_NAME
 
 
   override val indexName: String get() = SDK_STUBS_STORAGE_NAME
 
-  override val indexExternalizer: SerializedStubTreeDataExternalizer get() = SerializedStubTreeDataExternalizer(mySerializationManager, StubForwardIndexExternalizer.createFileLocalExternalizer(), false)
+  override val indexExternalizer: SerializedStubTreeDataExternalizer get() = SerializedStubTreeDataExternalizer(mySerializationManager, StubForwardIndexExternalizer.createFileLocalExternalizer())
 
   companion object {
     const val PREBUILT_INDICES_PATH_PROPERTY = "prebuilt_indices_path"
 
   companion object {
     const val PREBUILT_INDICES_PATH_PROPERTY = "prebuilt_indices_path"
index 637047706dba4a9fc7d01bf21e8ffbf94f664f68..df7ac59107e96a6a804d070ee066ab447ce1175a 100644 (file)
@@ -38,16 +38,13 @@ public final class SerializedStubTree {
   private final @NotNull SerializationManagerEx mySerializationManager;
   private final @NotNull StubForwardIndexExternalizer<?> myStubIndexesExternalizer;
 
   private final @NotNull SerializationManagerEx mySerializationManager;
   private final @NotNull StubForwardIndexExternalizer<?> myStubIndexesExternalizer;
 
-  private final @Nullable IndexingStampInfo myIndexingStampInfo;
-
   public SerializedStubTree(byte @NotNull [] treeBytes,
                             int treeByteLength,
                             byte @NotNull [] indexedStubBytes,
                             int indexedStubByteLength,
                             @Nullable Map<StubIndexKey<?, ?>, Map<Object, StubIdList>> indexedStubs,
                             @NotNull StubForwardIndexExternalizer<?> stubIndexesExternalizer,
   public SerializedStubTree(byte @NotNull [] treeBytes,
                             int treeByteLength,
                             byte @NotNull [] indexedStubBytes,
                             int indexedStubByteLength,
                             @Nullable Map<StubIndexKey<?, ?>, Map<Object, StubIdList>> indexedStubs,
                             @NotNull StubForwardIndexExternalizer<?> stubIndexesExternalizer,
-                            @NotNull SerializationManagerEx serializationManager,
-                            @Nullable IndexingStampInfo indexingStampInfo) {
+                            @NotNull SerializationManagerEx serializationManager) {
     myTreeBytes = treeBytes;
     myTreeByteLength = treeByteLength;
     myIndexedStubBytes = indexedStubBytes;
     myTreeBytes = treeBytes;
     myTreeByteLength = treeByteLength;
     myIndexedStubBytes = indexedStubBytes;
@@ -55,13 +52,11 @@ public final class SerializedStubTree {
     myIndexedStubs = indexedStubs;
     myStubIndexesExternalizer = stubIndexesExternalizer;
     mySerializationManager = serializationManager;
     myIndexedStubs = indexedStubs;
     myStubIndexesExternalizer = stubIndexesExternalizer;
     mySerializationManager = serializationManager;
-    myIndexingStampInfo = indexingStampInfo;
   }
 
   public static @NotNull SerializedStubTree serializeStub(@NotNull Stub rootStub,
                                                           @NotNull SerializationManagerEx serializationManager,
   }
 
   public static @NotNull SerializedStubTree serializeStub(@NotNull Stub rootStub,
                                                           @NotNull SerializationManagerEx serializationManager,
-                                                          @NotNull StubForwardIndexExternalizer<?> forwardIndexExternalizer,
-                                                          @Nullable IndexingStampInfo indexingStampInfo) throws IOException {
+                                                          @NotNull StubForwardIndexExternalizer<?> forwardIndexExternalizer) throws IOException {
     final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
     serializationManager.serialize(rootStub, bytes);
     byte[] treeBytes = bytes.getInternalBuffer();
     final BufferExposingByteArrayOutputStream bytes = new BufferExposingByteArrayOutputStream();
     serializationManager.serialize(rootStub, bytes);
     byte[] treeBytes = bytes.getInternalBuffer();
@@ -79,8 +74,7 @@ public final class SerializedStubTree {
       indexedStubByteLength,
       indexedStubs,
       forwardIndexExternalizer,
       indexedStubByteLength,
       indexedStubs,
       forwardIndexExternalizer,
-      serializationManager,
-      indexingStampInfo
+      serializationManager
     );
   }
 
     );
   }
 
@@ -110,13 +104,8 @@ public final class SerializedStubTree {
       reSerializedIndexByteLength,
       myIndexedStubs,
       newForwardIndexSerializer,
       reSerializedIndexByteLength,
       myIndexedStubs,
       newForwardIndexSerializer,
-      newSerializationManager,
-      myIndexingStampInfo);
-  }
-
-  @Nullable
-  IndexingStampInfo getIndexingStampInfo() {
-    return myIndexingStampInfo;
+      newSerializationManager
+    );
   }
 
   @ApiStatus.Internal
   }
 
   @ApiStatus.Internal
@@ -162,8 +151,7 @@ public final class SerializedStubTree {
                                   myIndexedStubByteLength,
                                   myIndexedStubs,
                                   myStubIndexesExternalizer,
                                   myIndexedStubByteLength,
                                   myIndexedStubs,
                                   myStubIndexesExternalizer,
-                                  mySerializationManager,
-                                  myIndexingStampInfo);
+                                  mySerializationManager);
   }
 
   @Override
   }
 
   @Override
index c4197f1f3c0e39f1fdcb129eb786ab769fb5a529..ecceb34943816c4660d9773f9bff7881aba9b7c8 100644 (file)
@@ -1,12 +1,13 @@
 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package com.intellij.psi.stubs;
 
 // Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
 package com.intellij.psi.stubs;
 
+import com.intellij.util.CompressionUtil;
 import com.intellij.util.io.DataExternalizer;
 import com.intellij.util.io.DataInputOutputUtil;
 import com.intellij.util.io.DataExternalizer;
 import com.intellij.util.io.DataInputOutputUtil;
+import com.intellij.util.io.PersistentHashMapValueStorage;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.DataInput;
 import org.jetbrains.annotations.NotNull;
 
 import java.io.DataInput;
-import java.io.DataInputStream;
 import java.io.DataOutput;
 import java.io.IOException;
 
 import java.io.DataOutput;
 import java.io.IOException;
 
@@ -14,32 +15,30 @@ public class SerializedStubTreeDataExternalizer implements DataExternalizer<Seri
   @NotNull
   private final SerializationManagerEx mySerializationManager;
   private final StubForwardIndexExternalizer<?> myStubIndexesExternalizer;
   @NotNull
   private final SerializationManagerEx mySerializationManager;
   private final StubForwardIndexExternalizer<?> myStubIndexesExternalizer;
-  private final boolean mySaveIndexingStamp;
 
 
-  public SerializedStubTreeDataExternalizer(@NotNull SerializationManagerEx manager,
-                                            @NotNull StubForwardIndexExternalizer<?> externalizer,
-                                            boolean saveIndexingStamp) {
+  public SerializedStubTreeDataExternalizer(@NotNull SerializationManagerEx manager, @NotNull StubForwardIndexExternalizer<?> externalizer) {
     mySerializationManager = manager;
     myStubIndexesExternalizer = externalizer;
     mySerializationManager = manager;
     myStubIndexesExternalizer = externalizer;
-    mySaveIndexingStamp = saveIndexingStamp;
   }
 
   @Override
   public final void save(@NotNull final DataOutput out, @NotNull final SerializedStubTree tree) throws IOException {
   }
 
   @Override
   public final void save(@NotNull final DataOutput out, @NotNull final SerializedStubTree tree) throws IOException {
-    DataInputOutputUtil.writeINT(out, tree.myTreeByteLength);
-    out.write(tree.myTreeBytes, 0, tree.myTreeByteLength);
-    DataInputOutputUtil.writeINT(out, tree.myIndexedStubByteLength);
-    out.write(tree.myIndexedStubBytes, 0, tree.myIndexedStubByteLength);
-    IndexingStampInfo indexingStampInfo = tree.getIndexingStampInfo();
-    if (indexingStampInfo != null && mySaveIndexingStamp) {
-      indexingStampInfo.save(out);
+    if (PersistentHashMapValueStorage.COMPRESSION_ENABLED) {
+      DataInputOutputUtil.writeINT(out, tree.myTreeByteLength);
+      out.write(tree.myTreeBytes, 0, tree.myTreeByteLength);
+      DataInputOutputUtil.writeINT(out, tree.myIndexedStubByteLength);
+      out.write(tree.myIndexedStubBytes, 0, tree.myIndexedStubByteLength);
+    }
+    else {
+      CompressionUtil.writeCompressed(out, tree.myTreeBytes, 0, tree.myTreeByteLength);
+      CompressionUtil.writeCompressed(out, tree.myIndexedStubBytes, 0, tree.myIndexedStubByteLength);
     }
   }
 
   @NotNull
   @Override
   public final SerializedStubTree read(@NotNull final DataInput in) throws IOException {
     }
   }
 
   @NotNull
   @Override
   public final SerializedStubTree read(@NotNull final DataInput in) throws IOException {
-    {
+    if (PersistentHashMapValueStorage.COMPRESSION_ENABLED) {
       int serializedStubsLength = DataInputOutputUtil.readINT(in);
       byte[] bytes = new byte[serializedStubsLength];
       in.readFully(bytes);
       int serializedStubsLength = DataInputOutputUtil.readINT(in);
       byte[] bytes = new byte[serializedStubsLength];
       in.readFully(bytes);
@@ -48,15 +47,14 @@ public class SerializedStubTreeDataExternalizer implements DataExternalizer<Seri
       indexedStubByteLength = DataInputOutputUtil.readINT(in);
       indexedStubBytes = new byte[indexedStubByteLength];
       in.readFully(indexedStubBytes);
       indexedStubByteLength = DataInputOutputUtil.readINT(in);
       indexedStubBytes = new byte[indexedStubByteLength];
       in.readFully(indexedStubBytes);
-      IndexingStampInfo indexingStampInfo = mySaveIndexingStamp ? IndexingStampInfo.read((DataInputStream)in) : null;
-      return new SerializedStubTree(bytes,
-                                    bytes.length,
-                                    indexedStubBytes,
-                                    indexedStubByteLength,
-                                    null,
-                                    myStubIndexesExternalizer,
-                                    mySerializationManager,
-                                    indexingStampInfo);
+      return new SerializedStubTree(bytes, bytes.length, indexedStubBytes, indexedStubByteLength,
+                                    null, myStubIndexesExternalizer, mySerializationManager);
+    }
+    else {
+      byte[] treeBytes = CompressionUtil.readCompressed(in);
+      byte[] indexedStubBytes = CompressionUtil.readCompressed(in);
+      return new SerializedStubTree(treeBytes, treeBytes.length, indexedStubBytes, indexedStubBytes.length,
+                                    null, myStubIndexesExternalizer, mySerializationManager);
     }
   }
 }
     }
   }
 }
index 81c2990ce20a95074e1005ba58bf47f65cd4305a..1b6617d619b112c04e63c61730960fa0b24bd1ea 100644 (file)
@@ -103,7 +103,7 @@ final class StubTreeLoaderImpl extends StubTreeLoader {
     if (size == 1) {
       SerializedStubTree stubTree = datas.values().iterator().next();
 
     if (size == 1) {
       SerializedStubTree stubTree = datas.values().iterator().next();
 
-      if (vFile instanceof VirtualFileWithId && !checkLengthMatch(project, vFile, wasIndexedAlready, document, saved, stubTree.getIndexingStampInfo())) {
+      if (vFile instanceof VirtualFileWithId && !checkLengthMatch(project, vFile, wasIndexedAlready, document, saved)) {
         return null;
       }
 
         return null;
       }
 
@@ -136,34 +136,23 @@ final class StubTreeLoaderImpl extends StubTreeLoader {
                                    VirtualFile vFile,
                                    boolean wasIndexedAlready,
                                    Document document,
                                    VirtualFile vFile,
                                    boolean wasIndexedAlready,
                                    Document document,
-                                   boolean saved,
-                                   @Nullable IndexingStampInfo indexingStampFromIndex) {
+                                   boolean saved) {
     PsiFile cachedPsi = PsiManagerEx.getInstanceEx(project).getFileManager().getCachedPsiFile(vFile);
     PsiFile cachedPsi = PsiManagerEx.getInstanceEx(project).getFileManager().getCachedPsiFile(vFile);
-    IndexingStampInfo indexingStampFromAttributes = getIndexingStampInfoFromAttributes(vFile);
-    if (indexingStampFromAttributes != null &&
-        !indexingStampFromAttributes.contentLengthMatches(vFile.getLength(), getCurrentTextContentLength(project, vFile, document, cachedPsi))) {
-      diagnoseLengthMismatch(vFile,
-                             wasIndexedAlready,
-                             document,
-                             saved,
-                             cachedPsi,
-                             indexingStampFromAttributes,
-                             indexingStampFromIndex);
+    IndexingStampInfo indexingStampInfo = getIndexingStampInfo(vFile);
+    if (indexingStampInfo != null &&
+        !indexingStampInfo.contentLengthMatches(vFile.getLength(), getCurrentTextContentLength(project, vFile, document, cachedPsi))) {
+      diagnoseLengthMismatch(vFile, wasIndexedAlready, document, saved, cachedPsi);
       return false;
     }
     return true;
   }
 
       return false;
     }
     return true;
   }
 
-  private static void diagnoseLengthMismatch(@NotNull VirtualFile vFile,
-                                             boolean wasIndexedAlready,
-                                             @Nullable Document document,
-                                             boolean saved,
-                                             @Nullable PsiFile cachedPsi,
-                                             @Nullable IndexingStampInfo indexingStampInfoFromAttributes,
-                                             @Nullable IndexingStampInfo indexingStampInfoFromIndex) {
-    String message = "Outdated stub in index: " + vFile +
-                     ", \n indexing stamp from attributes: " + indexingStampInfoFromAttributes +
-                     ", \n indexing stamp from index: " + indexingStampInfoFromIndex +
+  private void diagnoseLengthMismatch(@NotNull VirtualFile vFile,
+                                      boolean wasIndexedAlready,
+                                      @Nullable Document document,
+                                      boolean saved,
+                                      @Nullable PsiFile cachedPsi) {
+    String message = "Outdated stub in index: " + vFile + " " + getIndexingStampInfo(vFile) +
                      ", doc=" + document +
                      ", docSaved=" + saved +
                      ", wasIndexedAlready=" + wasIndexedAlready +
                      ", doc=" + document +
                      ", docSaved=" + saved +
                      ", wasIndexedAlready=" + wasIndexedAlready +
@@ -271,8 +260,8 @@ final class StubTreeLoaderImpl extends StubTreeLoader {
   }
 
   @Override
   }
 
   @Override
-  protected IndexingStampInfo getIndexingStampInfoFromAttributes(@NotNull VirtualFile file) {
-    return StubUpdatingIndex.readSavedIndexingStampInfoFromAttribute(file);
+  protected IndexingStampInfo getIndexingStampInfo(@NotNull VirtualFile file) {
+    return StubUpdatingIndex.readSavedIndexingStampInfo(file);
   }
 
   @Override
   }
 
   @Override
index bb7c9718e499fb22aa917c993cf6174b9a767bfd..ea2fb70f244946e9ee5c99f7583fc93299dfea37 100644 (file)
@@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.newvfs.FileAttribute;
 import com.intellij.openapi.vfs.newvfs.persistent.FSRecords;
 import com.intellij.psi.tree.IFileElementType;
 import com.intellij.psi.tree.IStubFileElementType;
 import com.intellij.openapi.vfs.newvfs.persistent.FSRecords;
 import com.intellij.psi.tree.IFileElementType;
 import com.intellij.psi.tree.IStubFileElementType;
+import com.intellij.util.BitUtil;
 import com.intellij.util.KeyedLazyInstance;
 import com.intellij.util.SystemProperties;
 import com.intellij.util.indexing.*;
 import com.intellij.util.KeyedLazyInstance;
 import com.intellij.util.SystemProperties;
 import com.intellij.util.indexing.*;
@@ -35,10 +36,7 @@ import com.intellij.util.indexing.impl.forward.IntMapForwardIndex;
 import com.intellij.util.indexing.impl.storage.TransientChangesIndexStorage;
 import com.intellij.util.indexing.impl.storage.VfsAwareMapReduceIndex;
 import com.intellij.util.indexing.snapshot.SnapshotInputMappings;
 import com.intellij.util.indexing.impl.storage.TransientChangesIndexStorage;
 import com.intellij.util.indexing.impl.storage.VfsAwareMapReduceIndex;
 import com.intellij.util.indexing.snapshot.SnapshotInputMappings;
-import com.intellij.util.io.DataExternalizer;
-import com.intellij.util.io.EnumeratorStringDescriptor;
-import com.intellij.util.io.KeyDescriptor;
-import com.intellij.util.io.PersistentHashMapValueStorage;
+import com.intellij.util.io.*;
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
 import org.jetbrains.annotations.NotNull;
 import org.jetbrains.annotations.Nullable;
 
@@ -67,18 +65,15 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
 
   @NotNull
   private final SerializationManagerEx mySerializationManager;
 
   @NotNull
   private final SerializationManagerEx mySerializationManager;
-  private final boolean mySaveIndexingStampToIndex;
 
   public StubUpdatingIndex() {
 
   public StubUpdatingIndex() {
-    this(StubForwardIndexExternalizer.getIdeUsedExternalizer(), SerializationManagerEx.getInstanceEx(), true);
+    this(StubForwardIndexExternalizer.getIdeUsedExternalizer(), SerializationManagerEx.getInstanceEx());
   }
 
   public StubUpdatingIndex(@NotNull StubForwardIndexExternalizer<?> stubIndexesExternalizer,
   }
 
   public StubUpdatingIndex(@NotNull StubForwardIndexExternalizer<?> stubIndexesExternalizer,
-                           @NotNull SerializationManagerEx serializationManager,
-                           boolean saveIndexingStampToIndex) {
+                           @NotNull SerializationManagerEx serializationManager) {
     myStubIndexesExternalizer = stubIndexesExternalizer;
     mySerializationManager = serializationManager;
     myStubIndexesExternalizer = stubIndexesExternalizer;
     mySerializationManager = serializationManager;
-    mySaveIndexingStampToIndex = saveIndexingStampToIndex;
   }
 
   @Override
   }
 
   @Override
@@ -176,11 +171,7 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
             }
             return null;
           }
             }
             return null;
           }
-          IndexingStampInfo indexingStampInfo = calculateIndexingStamp(inputData);
-          SerializedStubTree serializedStubTree = SerializedStubTree.serializeStub(stub,
-                                                                                   mySerializationManager,
-                                                                                   myStubIndexesExternalizer,
-                                                                                   indexingStampInfo);
+          SerializedStubTree serializedStubTree = SerializedStubTree.serializeStub(stub, mySerializationManager, myStubIndexesExternalizer);
           if (IndexDebugProperties.DEBUG) {
             assertDeserializedStubMatchesOriginalStub(serializedStubTree, stub);
           }
           if (IndexDebugProperties.DEBUG) {
             assertDeserializedStubMatchesOriginalStub(serializedStubTree, stub);
           }
@@ -242,10 +233,7 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
       if (stub == null) {
         return;
       }
       if (stub == null) {
         return;
       }
-      SerializedStubTree actualTree = SerializedStubTree.serializeStub(stub,
-                                                                       mySerializationManager,
-                                                                       myStubIndexesExternalizer,
-                                                                       prebuiltStubTree.getIndexingStampInfo());
+      SerializedStubTree actualTree = SerializedStubTree.serializeStub(stub, mySerializationManager, myStubIndexesExternalizer);
       if (!IndexDataComparer.INSTANCE.areStubTreesTheSame(actualTree, prebuiltStubTree)) {
         throw new RuntimeExceptionWithAttachments(
           "Prebuilt stub tree does not match actual stub tree",
       if (!IndexDataComparer.INSTANCE.areStubTreesTheSame(actualTree, prebuiltStubTree)) {
         throw new RuntimeExceptionWithAttachments(
           "Prebuilt stub tree does not match actual stub tree",
@@ -259,6 +247,8 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
     }
   }
 
     }
   }
 
+  private static final byte IS_BINARY_MASK = 1;
+  private static final byte BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK = 1 << 1;
   @NotNull
   private static IndexingStampInfo calculateIndexingStamp(@NotNull FileContent content) {
     VirtualFile file = content.getFile();
   @NotNull
   private static IndexingStampInfo calculateIndexingStamp(@NotNull FileContent content) {
     VirtualFile file = content.getFile();
@@ -269,10 +259,21 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
     return new IndexingStampInfo(file.getTimeStamp(), byteLength, contentLength, isBinary);
   }
 
     return new IndexingStampInfo(file.getTimeStamp(), byteLength, contentLength, isBinary);
   }
 
-  static void saveIndexingStampInfoToAttribute(@Nullable IndexingStampInfo indexingStampInfo, int fileId) {
+  static void saveIndexingStampInfo(@Nullable IndexingStampInfo indexingStampInfo, int fileId) {
     try (DataOutputStream stream = FSRecords.writeAttribute(fileId, INDEXED_STAMP)) {
       if (indexingStampInfo == null) return;
     try (DataOutputStream stream = FSRecords.writeAttribute(fileId, INDEXED_STAMP)) {
       if (indexingStampInfo == null) return;
-      indexingStampInfo.save(stream);
+      DataInputOutputUtil.writeTIME(stream, indexingStampInfo.indexingFileStamp);
+      DataInputOutputUtil.writeLONG(stream, indexingStampInfo.indexingByteLength);
+
+      boolean lengthsAreTheSame = indexingStampInfo.indexingCharLength == indexingStampInfo.indexingByteLength;
+      byte flags = 0;
+      flags = BitUtil.set(flags, IS_BINARY_MASK, indexingStampInfo.isBinary);
+      flags = BitUtil.set(flags, BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK, lengthsAreTheSame);
+      stream.writeByte(flags);
+
+      if (!lengthsAreTheSame && !indexingStampInfo.isBinary) {
+        DataInputOutputUtil.writeINT(stream, indexingStampInfo.indexingCharLength);
+      }
     }
     catch (IOException e) {
       LOG.error(e);
     }
     catch (IOException e) {
       LOG.error(e);
@@ -280,9 +281,29 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
   }
 
   @Nullable
   }
 
   @Nullable
-  static IndexingStampInfo readSavedIndexingStampInfoFromAttribute(@NotNull VirtualFile file) {
+  static IndexingStampInfo readSavedIndexingStampInfo(@NotNull VirtualFile file) {
     try (DataInputStream stream = INDEXED_STAMP.readAttribute(file)) {
     try (DataInputStream stream = INDEXED_STAMP.readAttribute(file)) {
-      return IndexingStampInfo.read(stream);
+      if (stream == null || stream.available() <= 0) {
+        return null;
+      }
+      long stamp = DataInputOutputUtil.readTIME(stream);
+      long byteLength = DataInputOutputUtil.readLONG(stream);
+
+      byte flags = stream.readByte();
+      boolean isBinary = BitUtil.isSet(flags, IS_BINARY_MASK);
+      boolean readOnlyOneLength = BitUtil.isSet(flags, BYTE_AND_CHAR_LENGTHS_ARE_THE_SAME_MASK);
+
+      int charLength;
+      if (isBinary) {
+        charLength = -1;
+      }
+      else if (readOnlyOneLength) {
+        charLength = (int)byteLength;
+      }
+      else {
+        charLength = DataInputOutputUtil.readINT(stream);
+      }
+      return new IndexingStampInfo(stamp, byteLength, charLength, isBinary);
     }
     catch (IOException e) {
       LOG.error(e);
     }
     catch (IOException e) {
       LOG.error(e);
@@ -294,7 +315,7 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
   @Override
   public DataExternalizer<SerializedStubTree> getValueExternalizer() {
     ensureSerializationManagerInitialized(mySerializationManager);
   @Override
   public DataExternalizer<SerializedStubTree> getValueExternalizer() {
     ensureSerializationManagerInitialized(mySerializationManager);
-    return new SerializedStubTreeDataExternalizer(mySerializationManager, myStubIndexesExternalizer, mySaveIndexingStampToIndex);
+    return new SerializedStubTreeDataExternalizer(mySerializationManager, myStubIndexesExternalizer);
   }
 
   @NotNull
   }
 
   @NotNull
@@ -407,7 +428,7 @@ public final class StubUpdatingIndex extends SingleEntryFileBasedIndexExtension<
         try {
           Boolean result = indexUpdateComputable.compute();
           if (Boolean.TRUE.equals(result)) {
         try {
           Boolean result = indexUpdateComputable.compute();
           if (Boolean.TRUE.equals(result)) {
-            saveIndexingStampInfoToAttribute(indexingStampInfo, inputId);
+            saveIndexingStampInfo(indexingStampInfo, inputId);
           }
           return result;
         } catch (ProcessCanceledException e) {
           }
           return result;
         } catch (ProcessCanceledException e) {
index d486daa08023fc3a8599367c92e3e3152c4eb2fc..56003845d9e9f59956874f24598e9789a6c6e46c 100644 (file)
@@ -50,7 +50,7 @@ open class StubsGenerator(private val stubsVersion: String, private val stubsSto
       return null
     }
 
       return null
     }
 
-    return SerializedStubTree.serializeStub(stub, serializationManager, StubForwardIndexExternalizer.createFileLocalExternalizer(), null)
+    return SerializedStubTree.serializeStub(stub, serializationManager, StubForwardIndexExternalizer.createFileLocalExternalizer())
   }
 
   override fun createStorage(stubsStorageFilePath: String): PersistentHashMap<HashCode, SerializedStubTree> {
   }
 
   override fun createStorage(stubsStorageFilePath: String): PersistentHashMap<HashCode, SerializedStubTree> {
@@ -115,12 +115,9 @@ fun mergeStubs(paths: List<String>, stubsFilePath: String, stubsFileName: String
             storage.get(key).stub
 
             val stub = value.stub
             storage.get(key).stub
 
             val stub = value.stub
-            val newStubTree2 = SerializedStubTree.serializeStub(
-              stub,
-              newSerializationManager,
-              newForwardIndexSerializer,
-              null
-            )
+            val newStubTree2 = SerializedStubTree.serializeStub(stub,
+                                                                newSerializationManager,
+                                                                newForwardIndexSerializer)
 
             TestCase.assertTrue(newStubTree == newStubTree2) // wtf!!! why are they equal now???
           }
 
             TestCase.assertTrue(newStubTree == newStubTree2) // wtf!!! why are they equal now???
           }