diff --git a/platform/lang-api/src/com/intellij/util/indexing/ID.java b/platform/lang-api/src/com/intellij/util/indexing/ID.java index e400793c745c..463fcaee4276 100644 --- a/platform/lang-api/src/com/intellij/util/indexing/ID.java +++ b/platform/lang-api/src/com/intellij/util/indexing/ID.java @@ -78,6 +78,8 @@ public class ID { } int n = ourNameToIdRegistry.size() + 1; + assert n <= Short.MAX_VALUE : "Number of indices exceeded"; + ourNameToIdRegistry.put(name, n); writeEnumFile(); diff --git a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java index 07591f7c4d6f..76f69436607c 100644 --- a/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java +++ b/platform/lang-impl/src/com/intellij/util/indexing/FileBasedIndex.java @@ -101,14 +101,7 @@ public class FileBasedIndex implements ApplicationComponent { private final Set> myNotRequiringContentIndices = new HashSet>(); private final Set myNoLimitCheckTypes = new HashSet(); - private final PerIndexDocumentMap myLastIndexedDocStamps = new PerIndexDocumentMap() { - @NotNull - @Override - protected Long createDefault(@NotNull Document document) { - return 0L; - } - }; - + private final PerIndexDocumentVersionMap myLastIndexedDocStamps = new PerIndexDocumentVersionMap(); private final ChangedFilesCollector myChangedFilesCollector; private final List myIndexableSets = ContainerUtil.createEmptyCOWList(); @@ -354,7 +347,6 @@ public class FileBasedIndex implements ApplicationComponent { * @param isCurrentVersionCorrupted */ private boolean registerIndexer(final FileBasedIndexExtension extension, final boolean isCurrentVersionCorrupted) throws IOException { - boolean versionChanged = false; final ID name = extension.getName(); final int version = extension.getVersion(); if (!extension.dependsOnFileContent()) { @@ -363,6 +355,7 @@ public class FileBasedIndex implements ApplicationComponent { myIndexIdToVersionMap.put(name, version); final File versionFile = IndexInfrastructure.getVersionFile(name); final boolean versionFileExisted = versionFile.exists(); + boolean versionChanged = false; if (isCurrentVersionCorrupted || IndexInfrastructure.versionDiffers(versionFile, version)) { if (!isCurrentVersionCorrupted && versionFileExisted) { versionChanged = true; @@ -1181,7 +1174,7 @@ public class FileBasedIndex implements ApplicationComponent { } final long currentDocStamp = content.getModificationStamp(); - if (currentDocStamp != myLastIndexedDocStamps.getAndSet(document, requestedIndexId, currentDocStamp).longValue()) { + if (currentDocStamp != myLastIndexedDocStamps.getAndSet(document, requestedIndexId, currentDocStamp)) { final Ref exRef = new Ref(null); ProgressManager.getInstance().executeNonCancelableSection(new Runnable() { public void run() { @@ -1770,10 +1763,10 @@ public class FileBasedIndex implements ApplicationComponent { if (file instanceof VirtualFileWithId) { try { - boolean oldStuff = true; if (file instanceof NewVirtualFile) { file.putUserData(NewVirtualFile.FILE_TYPE_KEY, file.getFileType()); } + boolean oldStuff = true; if (!isTooLarge(file)) { for (ID indexId : myIndices.keySet()) { try { diff --git a/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentMap.java b/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentMap.java deleted file mode 100644 index 06c42bdb001b..000000000000 --- a/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentMap.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package com.intellij.util.indexing; - -import com.intellij.openapi.editor.Document; -import com.intellij.util.containers.ConcurrentFactoryMap; -import com.intellij.util.containers.ConcurrentWeakFactoryMap; - -import java.util.Map; - -/** - * @author Dmitry Avdeev - * @author peter - */ -public abstract class PerIndexDocumentMap { - - private final Map> myVersions = new ConcurrentWeakFactoryMap>() { - protected Map create(final Document document) { - return new ConcurrentFactoryMap() { - protected T create(ID key) { - return createDefault(document); - } - }; - } - }; - - public T get(Document document, ID indexId) { - return myVersions.get(document).get(indexId); - } - - public void put(Document document, ID indexId, T value) { - myVersions.get(document).put(indexId, value); - } - - public synchronized T getAndSet(Document document, ID indexId, T value) { - T old = get(document, indexId); - put(document, indexId, value); - return old; - } - - public void clear() { - myVersions.clear(); - } - - protected abstract T createDefault(Document document); -} diff --git a/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentVersionMap.java b/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentVersionMap.java new file mode 100644 index 000000000000..316e114b1dbe --- /dev/null +++ b/platform/lang-impl/src/com/intellij/util/indexing/PerIndexDocumentVersionMap.java @@ -0,0 +1,72 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.intellij.util.indexing; + +import com.intellij.openapi.editor.Document; +import com.intellij.openapi.util.Key; +import com.intellij.openapi.util.UserDataHolderEx; +import org.jetbrains.annotations.NotNull; + +import java.util.ArrayList; +import java.util.List; + +/** + * @author Dmitry Avdeev + * @author peter + */ +public class PerIndexDocumentVersionMap { + private volatile int mapVersion; + private static class IdVersionInfo { + private final ID id; + private int mapVersion; + private long docVersion; + + private IdVersionInfo(@NotNull ID id, long docVersion, int mapVersion) { + this.docVersion = docVersion; + this.mapVersion = mapVersion; + this.id = id; + } + } + + private static final Key> KEY = Key.create("UnsavedDocIdVersionInfo"); + public long getAndSet(@NotNull Document document, @NotNull ID indexId, long value) { + List list = document.getUserData(KEY); + if (list == null) { + list = ((UserDataHolderEx)document).putUserDataIfAbsent(KEY, new ArrayList()); + } + + synchronized (list) { + for (IdVersionInfo info : list) { + if (info.id == indexId) { + long old = info.docVersion; + if (info.mapVersion != mapVersion) { + old = 0; + info.mapVersion = mapVersion; + } + info.docVersion = value; + return old; + } + } + list.add(new IdVersionInfo(indexId, value, mapVersion)); + return 0; + } + } + + public void clear() { + mapVersion++; + } +}