From 5d37fc84c6f187c0303dfe3d7a91214c32929dd7 Mon Sep 17 00:00:00 2001 From: Karsten Thoms Date: Tue, 30 Jun 2015 16:05:37 -0700 Subject: [PATCH] Bug 471103 Add caching for performance improvements of indexing process Change-Id: I56d3dea7e159f99fad083c6965a409c26b8de747 Signed-off-by: Karsten Thoms --- .../PDOMProjectIndexLocationConverter.java | 20 +++++++++++++++++-- .../core/pdom/indexer/FileExistsCache.java | 18 ++++++++++++++++- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java index 871ddd8e4d0..66333116641 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/dom/PDOMProjectIndexLocationConverter.java @@ -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 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 diff --git a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/FileExistsCache.java b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/FileExistsCache.java index 088dba93fb4..e10069d8528 100644 --- a/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/FileExistsCache.java +++ b/core/org.eclipse.cdt.core/parser/org/eclipse/cdt/internal/core/pdom/indexer/FileExistsCache.java @@ -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> fCache; + // Cache for recent results of isFile calls (bug 471103). + private final Map 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;