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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -8,11 +8,14 @@
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Andrew Ferguson (Symbian) - initial API and implementation
|
* Andrew Ferguson (Symbian) - initial API and implementation
|
||||||
* Markus Schorn (Wind River Systems)
|
* Markus Schorn (Wind River Systems)
|
||||||
|
* Karsten Thoms (itemis) - Bug 471103
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.dom;
|
package org.eclipse.cdt.internal.core.pdom.dom;
|
||||||
|
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
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.IIndexFileLocation;
|
||||||
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
import org.eclipse.cdt.core.index.IIndexLocationConverter;
|
||||||
|
@ -33,6 +36,8 @@ public class PDOMProjectIndexLocationConverter implements IIndexLocationConverte
|
||||||
final private IWorkspaceRoot fRoot;
|
final private IWorkspaceRoot fRoot;
|
||||||
final private String fFullPathPrefix;
|
final private String fFullPathPrefix;
|
||||||
final private boolean fIgnoreExternal;
|
final private boolean fIgnoreExternal;
|
||||||
|
// Cache for results of method fromInternalFormat (bug 471103).
|
||||||
|
final Map<String, IIndexFileLocation> fromInternalFormatCache = new HashMap<>();
|
||||||
|
|
||||||
public PDOMProjectIndexLocationConverter(IProject project) {
|
public PDOMProjectIndexLocationConverter(IProject project) {
|
||||||
this(project, false);
|
this(project, false);
|
||||||
|
@ -46,6 +51,12 @@ public class PDOMProjectIndexLocationConverter implements IIndexLocationConverte
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public IIndexFileLocation fromInternalFormat(String raw) {
|
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;
|
String fullPath = null;
|
||||||
URI uri= null;
|
URI uri= null;
|
||||||
if (raw.startsWith(EXTERNAL)) {
|
if (raw.startsWith(EXTERNAL)) {
|
||||||
|
@ -65,7 +76,12 @@ public class PDOMProjectIndexLocationConverter implements IIndexLocationConverte
|
||||||
uri = member.getLocationURI();
|
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
|
@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
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
|
@ -7,6 +7,7 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Markus Schorn - initial API and implementation
|
* Markus Schorn - initial API and implementation
|
||||||
|
* Karsten Thoms (itemis) - Bug 471103
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.core.pdom.indexer;
|
package org.eclipse.cdt.internal.core.pdom.indexer;
|
||||||
|
|
||||||
|
@ -44,6 +45,8 @@ public final class FileExistsCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Reference<Map<String, Content>> fCache;
|
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;
|
private final boolean fCaseInSensitive;
|
||||||
|
|
||||||
public FileExistsCache(boolean caseInsensitive) {
|
public FileExistsCache(boolean caseInsensitive) {
|
||||||
|
@ -54,6 +57,19 @@ public final class FileExistsCache {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFile(String path) {
|
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 parent;
|
||||||
String name;
|
String name;
|
||||||
File file = null;
|
File file = null;
|
||||||
|
|
Loading…
Add table
Reference in a new issue