diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/LRUCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/LRUCache.java new file mode 100644 index 00000000000..903a7b58a32 --- /dev/null +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/parser/util/LRUCache.java @@ -0,0 +1,32 @@ +/******************************************************************************* + * Copyright (c) 2011 Wind River Systems, Inc. and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Markus Schorn - initial API and implementation + *******************************************************************************/ + +package org.eclipse.cdt.internal.core.parser.util; + +import java.util.LinkedHashMap; +import java.util.Map.Entry; + +/** + * LRUCache based on {@link LinkedHashMap}. + */ +public class LRUCache extends LinkedHashMap { + private int fLimit; + + public LRUCache(int limit) { + super(16, 0.75f, true); + fLimit= limit; + } + + @Override + protected boolean removeEldestEntry(Entry eldest) { + return size() >= fLimit; + } +} diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java index 210edf3a751..841882a5e13 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/AbstractIndexerTask.java @@ -54,6 +54,7 @@ import org.eclipse.cdt.internal.core.index.IWritableIndex; import org.eclipse.cdt.internal.core.index.IndexBasedFileContentProvider; import org.eclipse.cdt.internal.core.parser.IMacroDictionary; import org.eclipse.cdt.internal.core.parser.scanner.InternalFileContentProvider; +import org.eclipse.cdt.internal.core.parser.util.LRUCache; import org.eclipse.cdt.utils.EFSExtensionManager; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; @@ -270,15 +271,15 @@ public abstract class AbstractIndexerTask extends PDOMWriter { return Integer.MAX_VALUE; } } - + protected enum MessageKind { parsingFileTask, errorWhileParsing, tooManyIndexProblems } private int fUpdateFlags= IIndexManager.UPDATE_ALL; private UnusedHeaderStrategy fIndexHeadersWithoutContext= UnusedHeaderStrategy.useDefaultLanguage; private boolean fIndexFilesWithoutConfiguration= true; private List fRequestsPerLinkage= new ArrayList(); - private Map fIndexContentCache= new HashMap(); - private Map fIndexFilesCache= new HashMap(); + private Map fIndexContentCache= new LRUCache(500); + private Map fIndexFilesCache= new LRUCache(5000); private Object[] fFilesToUpdate; private List fFilesToRemove = new ArrayList();