mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 09:45:39 +02:00
Bug 471103 Add caching for performance improvements of indexing process
Change-Id: I56d3dea7e159f99fad083c6965a409c26b8de747 Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
This commit is contained in:
parent
af52c9acc8
commit
5d37fc84c6
2 changed files with 35 additions and 3 deletions
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006, 2008 Symbian Software Ltd. and others.
|
||||
* Copyright (c) 2006, 2015 Symbian Software Ltd. 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
|
||||
|
@ -8,11 +8,14 @@
|
|||
* Contributors:
|
||||
* Andrew Ferguson (Symbian) - initial API and implementation
|
||||
* Markus Schorn (Wind River Systems)
|
||||
* Karsten Thoms (itemis) - Bug 471103
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.cdt.core.index.IIndexFileLocation;
|
||||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||
|
@ -33,6 +36,8 @@ public class PDOMProjectIndexLocationConverter implements IIndexLocationConverte
|
|||
final private IWorkspaceRoot fRoot;
|
||||
final private String fFullPathPrefix;
|
||||
final private boolean fIgnoreExternal;
|
||||
// Cache for results of method fromInternalFormat (bug 471103).
|
||||
final Map<String, IIndexFileLocation> fromInternalFormatCache = new HashMap<>();
|
||||
|
||||
public PDOMProjectIndexLocationConverter(IProject project) {
|
||||
this(project, false);
|
||||
|
@ -46,6 +51,12 @@ public class PDOMProjectIndexLocationConverter implements IIndexLocationConverte
|
|||
|
||||
@Override
|
||||
public IIndexFileLocation fromInternalFormat(String raw) {
|
||||
// Fast return when 'raw' was queried before (bug 471103).
|
||||
IIndexFileLocation cachedResult = fromInternalFormatCache.get(raw);
|
||||
if (cachedResult != null) {
|
||||
return cachedResult;
|
||||
}
|
||||
|
||||
String fullPath = null;
|
||||
URI uri= null;
|
||||
if (raw.startsWith(EXTERNAL)) {
|
||||
|
@ -65,7 +76,12 @@ public class PDOMProjectIndexLocationConverter implements IIndexLocationConverte
|
|||
uri = member.getLocationURI();
|
||||
}
|
||||
}
|
||||
return uri == null ? null : new IndexFileLocation(uri, fullPath);
|
||||
if (uri == null)
|
||||
return null;
|
||||
|
||||
IndexFileLocation location = new IndexFileLocation(uri, fullPath);
|
||||
fromInternalFormatCache.put(raw, location);
|
||||
return location;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2008, 2011 Wind River Systems, Inc. and others.
|
||||
* Copyright (c) 2008, 2015 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
|
||||
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Markus Schorn - initial API and implementation
|
||||
* Karsten Thoms (itemis) - Bug 471103
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||
|
||||
|
@ -44,6 +45,8 @@ public final class FileExistsCache {
|
|||
}
|
||||
|
||||
private Reference<Map<String, Content>> fCache;
|
||||
// Cache for recent results of isFile calls (bug 471103).
|
||||
private final Map<String, Boolean> fCacheIsFile = new HashMap<>();
|
||||
private final boolean fCaseInSensitive;
|
||||
|
||||
public FileExistsCache(boolean caseInsensitive) {
|
||||
|
@ -54,6 +57,19 @@ public final class FileExistsCache {
|
|||
}
|
||||
|
||||
public boolean isFile(String path) {
|
||||
// Fast return when path was already queried. The method is potentially called multiple times with
|
||||
// the same path on each return statement the returned value is stored in the cache (bug 471103).
|
||||
Boolean cachedResult = fCacheIsFile.get(path);
|
||||
if (!BYPASS_CACHE && cachedResult != null) {
|
||||
return cachedResult.booleanValue();
|
||||
}
|
||||
|
||||
boolean result = isFileInternal(path);
|
||||
fCacheIsFile.put(path, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private boolean isFileInternal(String path) {
|
||||
String parent;
|
||||
String name;
|
||||
File file = null;
|
||||
|
|
Loading…
Add table
Reference in a new issue