better structure after review results

This commit is contained in:
Maxim.Mossienko
2015-04-02 13:55:14 +02:00
parent fde7f6a333
commit 31a64e59c4
4 changed files with 27 additions and 31 deletions
@@ -42,6 +42,10 @@ import java.util.Set;
public abstract class FileBasedIndex implements BaseComponent {
public abstract void iterateIndexableFiles(@NotNull ContentIterator processor, @NotNull Project project, ProgressIndicator indicator);
public void iterateIndexableFilesConcurrently(@NotNull ContentIterator processor, @NotNull Project project, ProgressIndicator indicator) {
iterateIndexableFiles(processor, project, indicator);
}
public abstract void registerIndexableSet(@NotNull IndexableFileSet set, @Nullable Project project);
public abstract void removeIndexableSet(@NotNull IndexableFileSet set);
@@ -288,14 +288,16 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater
tasks.add(iteration);
}
if (ourConcurrentlyFlag.get() == Boolean.TRUE && Registry.is("idea.concurrent.scanning.files.to.index")) {
invoke2xConcurrently(tasks);
} else {
for(Runnable r:tasks) r.run();
}
invoke2xConcurrentlyIfPossible(tasks);
}
public static void invoke2xConcurrently(final List<Runnable> tasks) {
public static void invoke2xConcurrentlyIfPossible(final List<Runnable> tasks) {
if (tasks.size() == 1 ||
ApplicationManager.getApplication().isWriteAccessAllowed() ||
!Registry.is("idea.concurrent.scanning.files.to.index")) {
for(Runnable r:tasks) r.run();
return;
}
final ConcurrentLinkedQueue<Runnable> tasksQueue = new ConcurrentLinkedQueue<Runnable>(tasks);
Future<?> result = null;
if (tasks.size() > 1) {
@@ -327,8 +329,6 @@ public class PushedFilePropertiesUpdaterImpl extends PushedFilePropertiesUpdater
//});
}
public static final ThreadLocal<Boolean> ourConcurrentlyFlag = new ThreadLocal<Boolean>();
private void applyPushersToFile(final VirtualFile fileOrDir, final FilePropertyPusher[] pushers, final Object[] moduleValues) {
ApplicationManager.getApplication().runReadAction(new Runnable() {
@Override
@@ -2570,12 +2570,21 @@ public class FileBasedIndexImpl extends FileBasedIndex {
}
}
public static final ThreadLocal<Boolean> ourConcurrentlyFlag = new ThreadLocal<Boolean>();
@Override
public void iterateIndexableFilesConcurrently(@NotNull ContentIterator processor, @NotNull Project project, ProgressIndicator indicator) {
PushedFilePropertiesUpdaterImpl.invoke2xConcurrentlyIfPossible(collectScanRootRunnables(processor, project, indicator));
}
@Override
public void iterateIndexableFiles(@NotNull final ContentIterator processor, @NotNull final Project project, final ProgressIndicator indicator) {
for(Runnable r: collectScanRootRunnables(processor, project, indicator)) r.run();
}
private static @NotNull List<Runnable> collectScanRootRunnables(@NotNull final ContentIterator processor,
@NotNull final Project project,
final ProgressIndicator indicator) {
if (project.isDisposed()) {
return;
return Collections.emptyList();
}
List<Runnable> tasks = new ArrayList<Runnable>();
@@ -2604,7 +2613,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
//important not to depend on project here, to support per-project background reindex
// each client gives a project to FileBasedIndex
if (project.isDisposed()) {
return;
return null;
}
for (final VirtualFile root : IndexableSetContributor.getRootsToIndex(provider)) {
if (visitedRoots.add(root)) {
@@ -2656,12 +2665,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
}
}
}
if (ourConcurrentlyFlag.get() == Boolean.TRUE && Registry.is("idea.concurrent.scanning.files.to.index")) {
PushedFilePropertiesUpdaterImpl.invoke2xConcurrently(tasks);
} else {
for(Runnable r:tasks) r.run();
}
return tasks;
}
private static void iterateRecursively(@Nullable final VirtualFile root,
@@ -31,7 +31,6 @@ import com.intellij.openapi.roots.CollectingContentIterator;
import com.intellij.openapi.roots.ModuleRootAdapter;
import com.intellij.openapi.roots.ModuleRootEvent;
import com.intellij.openapi.roots.impl.PushedFilePropertiesUpdater;
import com.intellij.openapi.roots.impl.PushedFilePropertiesUpdaterImpl;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
@@ -63,13 +62,7 @@ public class UnindexedFilesUpdater extends DumbModeTask {
private void updateUnindexedFiles(ProgressIndicator indicator) {
long started = System.currentTimeMillis();
boolean canProceedConcurrently = !ApplicationManager.getApplication().isWriteAccessAllowed();
PushedFilePropertiesUpdaterImpl.ourConcurrentlyFlag.set(canProceedConcurrently);
try {
PushedFilePropertiesUpdater.getInstance(myProject).pushAllPropertiesNow();
} finally {
PushedFilePropertiesUpdaterImpl.ourConcurrentlyFlag.set(null);
}
PushedFilePropertiesUpdater.getInstance(myProject).pushAllPropertiesNow();
LOG.info("Pushed properties in " + (System.currentTimeMillis() - started) + " ms");
@@ -78,12 +71,7 @@ public class UnindexedFilesUpdater extends DumbModeTask {
CollectingContentIterator finder = myIndex.createContentIterator(indicator);
long l = System.currentTimeMillis();
FileBasedIndexImpl.ourConcurrentlyFlag.set(canProceedConcurrently);
try {
myIndex.iterateIndexableFiles(finder, myProject, indicator);
} finally {
FileBasedIndexImpl.ourConcurrentlyFlag.set(null);
}
myIndex.iterateIndexableFilesConcurrently(finder, myProject, indicator);
myIndex.filesUpdateEnumerationFinished();