Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 57246 Details for
Bug 138309
[index] Optimize index files path storage in DiskIndex and IndexManager
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Proposed patch
v02.txt (text/plain), 31.11 KB, created by
Frederic Fusier
on 2007-01-22 07:16:02 EST
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Frederic Fusier
Created:
2007-01-22 07:16:02 EST
Size:
31.11 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.jdt.core.tests.compiler >Index: src/org/eclipse/jdt/core/tests/util/Util.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/Util.java,v >retrieving revision 1.53 >diff -u -r1.53 Util.java >--- src/org/eclipse/jdt/core/tests/util/Util.java 20 Dec 2006 16:11:25 -0000 1.53 >+++ src/org/eclipse/jdt/core/tests/util/Util.java 22 Jan 2007 11:37:55 -0000 >@@ -919,6 +919,20 @@ > } > } > /** >+ * Return the stack trace element of the caller's caller. >+ */ >+public static StackTraceElement caller() { >+ StackTraceElement[] elements = new Exception().getStackTrace(); >+ int idx = 0, length=elements.length; >+ while (idx<length && !elements[idx++].getClassName().equals("org.eclipse.jdt.core.tests.util.Util")) { >+ // loop until JDT/Core class appears in the stack >+ } >+ if (idx < length) { >+ return elements[idx]; >+ } >+ return null; >+} >+/** > * Makes the given path a path using native path separators as returned by File.getPath() > * and trimming any extra slash. > */ >#P org.eclipse.jdt.core >Index: search/org/eclipse/jdt/internal/core/index/DiskIndex.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/DiskIndex.java,v >retrieving revision 1.54 >diff -u -r1.54 DiskIndex.java >--- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 11 Jan 2007 11:45:16 -0000 1.54 >+++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 22 Jan 2007 11:37:59 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2006 IBM Corporation and others. >+ * Copyright (c) 2000, 2007 IBM Corporation 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 >@@ -19,10 +19,11 @@ > import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; > import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; > import org.eclipse.jdt.internal.compiler.util.SimpleSet; >+import org.eclipse.jdt.internal.compiler.util.SimpleSetOfCharArray; > > public class DiskIndex { > >-String fileName; >+File indexFile; > > private int headerInfoOffset; > private int numberOfChunks; >@@ -37,7 +38,8 @@ > private HashtableOfObject categoryTables; // category name -> HashtableOfObject(words -> int[] of document #'s) or offset if not read yet > private char[] cachedCategoryName; > >-public static final String SIGNATURE= "INDEX VERSION 1.120"; //$NON-NLS-1$ >+public static final String SIGNATURE= "INDEX VERSION 1.121.2"; //$NON-NLS-1$ >+public static final char[] SIGNATURE_ARRAY= SIGNATURE.toCharArray(); > public static boolean DEBUG = false; > > private static final int RE_INDEXED = -1; >@@ -45,6 +47,8 @@ > > private static final int CHUNK_SIZE = 100; > >+private static final SimpleSetOfCharArray INTERNED_CATEGORY_NAMES = new SimpleSetOfCharArray(20); >+ > static class IntList { > > int size; >@@ -70,8 +74,8 @@ > } > > >-DiskIndex(String fileName) { >- this.fileName = fileName; >+DiskIndex(File file) { >+ this.indexFile = file; > > // clear cached items > this.headerInfoOffset = -1; >@@ -204,7 +208,7 @@ > private void cacheDocumentNames() throws IOException { > // will need all document names so get them now > this.cachedChunks = new String[this.numberOfChunks][]; >- DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(getIndexFile()), this.numberOfChunks > 5 ? 4096 : 2048)); >+ DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(this.indexFile), this.numberOfChunks > 5 ? 4096 : 2048)); > try { > stream.skip(this.chunkOffsets[0]); > for (int i = 0; i < this.numberOfChunks; i++) { >@@ -336,15 +340,12 @@ > } > } > File getIndexFile() { >- if (this.fileName == null) return null; >- >- return new File(this.fileName); >+ return this.indexFile; > } > void initialize(boolean reuseExistingFile) throws IOException { >- File indexFile = getIndexFile(); >- if (indexFile.exists()) { >+ if (this.indexFile.exists()) { > if (reuseExistingFile) { >- RandomAccessFile file = new RandomAccessFile(this.fileName, "r"); //$NON-NLS-1$ >+ RandomAccessFile file = new RandomAccessFile(this.indexFile, "r"); //$NON-NLS-1$ > try { > String signature = file.readUTF(); > if (!signature.equals(SIGNATURE)) >@@ -359,13 +360,14 @@ > return; > } > if (!indexFile.delete()) { >+ String fileName = this.indexFile.getPath(); > if (DEBUG) >- System.out.println("initialize - Failed to delete index " + this.fileName); //$NON-NLS-1$ >- throw new IOException("Failed to delete index " + this.fileName); //$NON-NLS-1$ >+ System.out.println("initialize - Failed to delete index " + fileName); //$NON-NLS-1$ >+ throw new IOException("Failed to delete index " + fileName); //$NON-NLS-1$ > } > } > if (indexFile.createNewFile()) { >- RandomAccessFile file = new RandomAccessFile(this.fileName, "rw"); //$NON-NLS-1$ >+ RandomAccessFile file = new RandomAccessFile(this.indexFile, "rw"); //$NON-NLS-1$ > try { > file.writeUTF(SIGNATURE); > file.writeInt(-1); // file is empty >@@ -373,19 +375,21 @@ > file.close(); > } > } else { >+ String fileName = this.indexFile.getPath(); > if (DEBUG) >- System.out.println("initialize - Failed to create new index " + this.fileName); //$NON-NLS-1$ >- throw new IOException("Failed to create new index " + this.fileName); //$NON-NLS-1$ >+ System.out.println("initialize - Failed to create new index " + fileName); //$NON-NLS-1$ >+ throw new IOException("Failed to create new index " + fileName); //$NON-NLS-1$ > } > } > private void initializeFrom(DiskIndex diskIndex, File newIndexFile) throws IOException { > if (newIndexFile.exists() && !newIndexFile.delete()) { // delete the temporary index file > if (DEBUG) >- System.out.println("initializeFrom - Failed to delete temp index " + this.fileName); //$NON-NLS-1$ >+ System.out.println("initializeFrom - Failed to delete temp index " + this.indexFile.getPath()); //$NON-NLS-1$ > } else if (!newIndexFile.createNewFile()) { >+ String fileName = this.indexFile.getPath(); > if (DEBUG) >- System.out.println("initializeFrom - Failed to create temp index " + this.fileName); //$NON-NLS-1$ >- throw new IOException("Failed to create temp index " + this.fileName); //$NON-NLS-1$ >+ System.out.println("initializeFrom - Failed to create temp index " + fileName); //$NON-NLS-1$ >+ throw new IOException("Failed to create temp index " + fileName); //$NON-NLS-1$ > } > > int size = diskIndex.categoryOffsets == null ? 8 : diskIndex.categoryOffsets.elementSize; >@@ -465,13 +469,13 @@ > if (previousLength == 0) return this; // nothing to do... memory index contained deleted documents that had never been saved > > // index is now empty since all the saved documents were removed >- DiskIndex newDiskIndex = new DiskIndex(this.fileName); >+ DiskIndex newDiskIndex = new DiskIndex(this.indexFile); > newDiskIndex.initialize(false); > return newDiskIndex; > } > >- DiskIndex newDiskIndex = new DiskIndex(this.fileName + ".tmp"); //$NON-NLS-1$ >- File newIndexFile = newDiskIndex.getIndexFile(); >+ DiskIndex newDiskIndex = new DiskIndex(new File(this.indexFile.getPath() + ".tmp")); //$NON-NLS-1$ >+ File newIndexFile = newDiskIndex.indexFile; > try { > newDiskIndex.initializeFrom(this, newIndexFile); > DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(newIndexFile, false), 2048)); >@@ -487,8 +491,7 @@ > for (int i = 0, l = names.length; i < l; i++) > if (names[i] != null) > newDiskIndex.copyQueryResults( >- (HashtableOfObject) memoryIndex.docsToReferences.get(names[i]), >- ((Integer) integerPositions[i]).intValue()); >+ (HashtableOfObject) memoryIndex.docsToReferences.get(names[i]), ((Integer) integerPositions[i]).intValue()); > } > indexedDocuments = null; // free up the space > >@@ -506,32 +509,34 @@ > newDiskIndex.writeOffsetToHeader(offsetToHeader); > > // rename file by deleting previous index file & renaming temp one >- File old = getIndexFile(); >+ File old = this.indexFile; > if (old.exists() && !old.delete()) { >+ String fileName = old.getPath(); > if (DEBUG) >- System.out.println("mergeWith - Failed to delete " + this.fileName); //$NON-NLS-1$ >- throw new IOException("Failed to delete index file " + this.fileName); //$NON-NLS-1$ >+ System.out.println("mergeWith - Failed to delete " + fileName); //$NON-NLS-1$ >+ throw new IOException("Failed to delete index file " + fileName); //$NON-NLS-1$ > } > if (!newIndexFile.renameTo(old)) { >+ String fileName = old.getPath(); > if (DEBUG) >- System.out.println("mergeWith - Failed to rename " + this.fileName); //$NON-NLS-1$ >- throw new IOException("Failed to rename index file " + this.fileName); //$NON-NLS-1$ >+ System.out.println("mergeWith - Failed to rename " + fileName); //$NON-NLS-1$ >+ throw new IOException("Failed to rename index file " + fileName); //$NON-NLS-1$ > } > } catch (IOException e) { > if (newIndexFile.exists() && !newIndexFile.delete()) > if (DEBUG) >- System.out.println("mergeWith - Failed to delete temp index " + newDiskIndex.fileName); //$NON-NLS-1$ >+ System.out.println("mergeWith - Failed to delete temp index " + newDiskIndex.indexFile.getPath()); //$NON-NLS-1$ > throw e; > } > >- newDiskIndex.fileName = this.fileName; >+ newDiskIndex.indexFile = this.indexFile; > return newDiskIndex; > } > private synchronized String[] readAllDocumentNames() throws IOException { > if (this.numberOfChunks <= 0) > return CharOperation.NO_STRINGS; > >- DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(getIndexFile()), this.numberOfChunks > 5 ? 4096 : 2048)); >+ DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(this.indexFile), this.numberOfChunks > 5 ? 4096 : 2048)); > try { > stream.skip(this.chunkOffsets[0]); > int lastIndex = this.numberOfChunks - 1; >@@ -564,7 +569,7 @@ > } > } > >- DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(getIndexFile()), 2048)); >+ DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(this.indexFile), 2048)); > HashtableOfObject categoryTable = null; > char[][] matchingWords = null; > int count = 0; >@@ -575,7 +580,7 @@ > try { > if (size < 0) { // DEBUG > System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$ >- System.err.println("file = "+getIndexFile()); //$NON-NLS-1$ >+ System.err.println("file = "+this.indexFile); //$NON-NLS-1$ > System.err.println("offset = "+offset); //$NON-NLS-1$ > System.err.println("size = "+size); //$NON-NLS-1$ > System.err.println("-------------------- END --------------------"); //$NON-NLS-1$ >@@ -585,7 +590,7 @@ > // DEBUG > oom.printStackTrace(); > System.err.println("-------------------- DEBUG --------------------"); //$NON-NLS-1$ >- System.err.println("file = "+getIndexFile()); //$NON-NLS-1$ >+ System.err.println("file = "+this.indexFile); //$NON-NLS-1$ > System.err.println("offset = "+offset); //$NON-NLS-1$ > System.err.println("size = "+size); //$NON-NLS-1$ > System.err.println("-------------------- END --------------------"); //$NON-NLS-1$ >@@ -615,16 +620,20 @@ > categoryTable.put(word, new Integer(arrayOffset)); // offset to array in the file > } > } >- this.categoryTables.put(categoryName, categoryTable); >+ this.categoryTables.put(INTERNED_CATEGORY_NAMES.get(categoryName), categoryTable); > // cache the table as long as its not too big > // in practice, some tables can be greater than 500K when they contain more than 10K elements >- this.cachedCategoryName = categoryTable.elementSize < 10000 ? categoryName : null; >+ this.cachedCategoryName = categoryTable.elementSize < 20000 ? categoryName : null; >+ if (DEBUG) { >+ Util.verbose("Index file "+this.indexFile+" was read to populate category table..."); //$NON-NLS-1$ //$NON-NLS-2$ >+ printCategoryTables(); >+ } > } finally { > stream.close(); > } > > if (matchingWords != null && count > 0) { >- stream = new DataInputStream(new BufferedInputStream(new FileInputStream(getIndexFile()), 2048)); >+ stream = new DataInputStream(new BufferedInputStream(new FileInputStream(this.indexFile), 2048)); > try { > stream.skip(firstOffset); > for (int i = 0; i < count; i++) // each array follows the previous one >@@ -688,7 +697,7 @@ > if (numberOfBytes < 0) > throw new IllegalArgumentException(); > byte[] bytes = new byte[numberOfBytes]; >- FileInputStream file = new FileInputStream(getIndexFile()); >+ FileInputStream file = new FileInputStream(this.indexFile); > try { > file.skip(start); > if (file.read(bytes, 0, numberOfBytes) != numberOfBytes) >@@ -708,7 +717,7 @@ > if (arrayOffset instanceof int[]) > return (int[]) arrayOffset; > >- DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(getIndexFile()), 2048)); >+ DataInputStream stream = new DataInputStream(new BufferedInputStream(new FileInputStream(this.indexFile), 2048)); > try { > stream.skip(((Integer) arrayOffset).intValue()); > return readDocumentArray(stream, stream.readInt()); >@@ -733,7 +742,7 @@ > int size = file.readInt(); > this.categoryOffsets = new HashtableOfIntValues(size); > for (int i = 0; i < size; i++) >- this.categoryOffsets.put(Util.readUTF(file), file.readInt()); // cache offset to category table >+ this.categoryOffsets.put(INTERNED_CATEGORY_NAMES.get(Util.readUTF(file)), file.readInt()); // cache offset to category table > this.categoryTables = new HashtableOfObject(3); > } > synchronized void startQuery() { >@@ -909,7 +918,7 @@ > } > private void writeOffsetToHeader(int offsetToHeader) throws IOException { > if (offsetToHeader > 0) { >- RandomAccessFile file = new RandomAccessFile(this.fileName, "rw"); //$NON-NLS-1$ >+ RandomAccessFile file = new RandomAccessFile(this.indexFile, "rw"); //$NON-NLS-1$ > try { > file.seek(this.headerInfoOffset); // offset to position in header > file.writeInt(offsetToHeader); >@@ -919,4 +928,66 @@ > } > } > } >+private void printCategoryTables() { >+ StringBuffer buffer = new StringBuffer(" - categoryTables:"); //$NON-NLS-1$ >+ int size = 0; >+ if (this.categoryTables == null) { >+ buffer.append(" null\n"); //$NON-NLS-1$ >+ } else { >+ char[][] categoryNames = this.categoryTables.keyTable; >+ Object[] tables = this.categoryTables.valueTable; >+ int length = categoryNames.length; >+ for (int i = 0; i < length; i++) { >+ if (categoryNames[i] != null) { >+ buffer.append("\n + "+new String(categoryNames[i])); //$NON-NLS-1$ >+ size += categoryNames[i].length + 16; >+ HashtableOfObject table = (HashtableOfObject) tables[i]; >+ buffer.append(" -> "); //$NON-NLS-1$ >+ if (table == null) { >+ buffer.append(" null\n"); //$NON-NLS-1$ >+ } else { >+ buffer.append(table.elementSize); >+ buffer.append(" int arrays"); //$NON-NLS-1$ >+ int offset = table.elementSize / 10; >+ int tableSize = 16; >+ for (int j=0, l=table.keyTable.length; j<l; j++) { >+ char[] key = table.keyTable[j]; >+ if (key != null) { >+ tableSize += key.length*2 + 16; >+ Object value = table.valueTable[j]; >+ if (value instanceof int[]) { >+ tableSize += (((int[]) value).length-1)*4 + 16; >+ } else if (value instanceof Integer) { >+ tableSize += 20; >+ } >+ if (offset == 0 || (j%offset) == 0) { >+ buffer.append("\n . "); //$NON-NLS-1$ >+ buffer.append(key); >+ buffer.append(" -> "); //$NON-NLS-1$ >+ buffer.append(value); >+ } >+ } >+ } >+ buffer.append("\n => size ~ "); //$NON-NLS-1$ >+ buffer.append(tableSize); >+ buffer.append('\n'); >+ size += tableSize; >+ } >+ } >+ } >+ buffer.append("\n => size ~ "); //$NON-NLS-1$ >+ buffer.append(size); >+ buffer.append('\n'); >+ } >+ buffer.append(" - cached category:"); //$NON-NLS-1$ >+ buffer.append(this.cachedCategoryName==null?"none":new String(this.cachedCategoryName)); //$NON-NLS-1$ >+ buffer.append('\n'); >+ Util.verbose(buffer.toString()); >+} >+/* (non-Javadoc) >+ * @see java.lang.Object#toString() >+ */ >+public String toString() { >+ return "DiskIndex for "+this.indexFile; //$NON-NLS-1$ >+} > } >Index: search/org/eclipse/jdt/internal/core/index/Index.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/Index.java,v >retrieving revision 1.24 >diff -u -r1.24 Index.java >--- search/org/eclipse/jdt/internal/core/index/Index.java 10 May 2006 18:03:51 -0000 1.24 >+++ search/org/eclipse/jdt/internal/core/index/Index.java 22 Jan 2007 11:37:59 -0000 >@@ -84,12 +84,12 @@ > } > > >-public Index(String fileName, String containerPath, boolean reuseExistingFile) throws IOException { >+public Index(File indexFile, String containerPath, boolean reuseExistingFile) throws IOException { > this.containerPath = containerPath; > this.monitor = new ReadWriteMonitor(); > > this.memoryIndex = new MemoryIndex(); >- this.diskIndex = new DiskIndex(fileName); >+ this.diskIndex = new DiskIndex(indexFile); > this.diskIndex.initialize(reuseExistingFile); > } > public void addIndexEntry(char[] category, char[] key, String containerRelativePath) { >Index: search/org/eclipse/jdt/internal/core/search/indexing/RemoveFolderFromIndex.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/RemoveFolderFromIndex.java,v >retrieving revision 1.29 >diff -u -r1.29 RemoveFolderFromIndex.java >--- search/org/eclipse/jdt/internal/core/search/indexing/RemoveFolderFromIndex.java 29 Mar 2006 03:13:59 -0000 1.29 >+++ search/org/eclipse/jdt/internal/core/search/indexing/RemoveFolderFromIndex.java 22 Jan 2007 11:38:00 -0000 >@@ -24,14 +24,12 @@ > IPath folderPath; > char[][] inclusionPatterns; > char[][] exclusionPatterns; >- IProject project; > > public RemoveFolderFromIndex(IPath folderPath, char[][] inclusionPatterns, char[][] exclusionPatterns, IProject project, IndexManager manager) { > super(project.getFullPath(), manager); > this.folderPath = folderPath; > this.inclusionPatterns = inclusionPatterns; > this.exclusionPatterns = exclusionPatterns; >- this.project = project; > } > public boolean execute(IProgressMonitor progressMonitor) { > >Index: search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java,v >retrieving revision 1.152 >diff -u -r1.152 IndexManager.java >--- search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 24 Nov 2006 01:32:07 -0000 1.152 >+++ search/org/eclipse/jdt/internal/core/search/indexing/IndexManager.java 22 Jan 2007 11:38:00 -0000 >@@ -27,6 +27,7 @@ > import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory; > import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; > import org.eclipse.jdt.internal.core.*; >+import org.eclipse.jdt.internal.core.index.DiskIndex; > import org.eclipse.jdt.internal.core.index.Index; > import org.eclipse.jdt.internal.core.search.BasicSearchEngine; > import org.eclipse.jdt.internal.core.search.PatternSearchJob; >@@ -46,12 +47,11 @@ > /* need to save ? */ > private boolean needToSave = false; > private static final CRC32 checksumCalculator = new CRC32(); >- private IPath javaPluginLocation = null; >+ private File indexesDirectory = null; > > /* can only replace a current state if its less than the new one */ > private SimpleLookupTable indexStates = null; >- private File savedIndexNamesFile = >- new File(getJavaPluginWorkingLocation().append("savedIndexNames.txt").toOSString()); //$NON-NLS-1$ >+ private File savedIndexNamesFile = new File(getIndexesDirectory(), "savedIndexNames.txt"); //$NON-NLS-1$ > public static Integer SAVED_STATE = new Integer(0); > public static Integer UPDATING_STATE = new Integer(1); > public static Integer UNKNOWN_STATE = new Integer(2); >@@ -106,9 +106,8 @@ > PatternSearchJob job = new PatternSearchJob(null, SearchEngine.getDefaultSearchParticipant(), scope, null); > Index[] selectedIndexes = job.getIndexes(null); > for (int j = 0, max = selectedIndexes.length; j < max; j++) { >- // TODO should use getJavaPluginWorkingLocation()+index simple name to avoid bugs such as https://bugs.eclipse.org/bugs/show_bug.cgi?id=62267 >- String path = selectedIndexes[j].getIndexFile().getAbsolutePath(); >- knownPaths.put(path, path); >+ String fileName = selectedIndexes[j].getIndexFile().getName(); >+ knownPaths.put(fileName, fileName); > } > > if (indexStates != null) { >@@ -127,12 +126,12 @@ > } > } > >- File indexesDirectory = new File(getJavaPluginWorkingLocation().toOSString()); >- if (indexesDirectory.isDirectory()) { >- File[] indexesFiles = indexesDirectory.listFiles(); >+ File idxDir = getIndexesDirectory(); >+ if (idxDir.isDirectory()) { >+ File[] indexesFiles = idxDir.listFiles(); > if (indexesFiles != null) { > for (int i = 0, indexesFilesLength = indexesFiles.length; i < indexesFilesLength; i++) { >- String fileName = indexesFiles[i].getAbsolutePath(); >+ String fileName = indexesFiles[i].getName(); > if (!knownPaths.containsKey(fileName) && fileName.toLowerCase().endsWith(".index")) { //$NON-NLS-1$ > if (VERBOSE) > Util.verbose("Deleting index file " + indexesFiles[i]); //$NON-NLS-1$ >@@ -148,10 +147,10 @@ > String pathString = containerPath.toOSString(); > checksumCalculator.reset(); > checksumCalculator.update(pathString.getBytes()); >- String fileName = Long.toString(checksumCalculator.getValue()) + ".index"; //$NON-NLS-1$ >- if (VERBOSE) >- Util.verbose("-> index name for " + pathString + " is " + fileName); //$NON-NLS-1$ //$NON-NLS-2$ >- indexLocation = getJavaPluginWorkingLocation().append(fileName).toOSString(); >+ indexLocation = Long.toString(checksumCalculator.getValue()) + ".index"; //$NON-NLS-1$ >+ if (VERBOSE) { >+ Util.verbose("-> index name for " + pathString + " is " + indexLocation); //$NON-NLS-1$ //$NON-NLS-2$ >+ } > this.indexLocations.put(containerPath, indexLocation); > } > return indexLocation; >@@ -223,10 +222,10 @@ > // index isn't cached, consider reusing an existing index file > String containerPathString = containerPath.getDevice() == null ? containerPath.toString() : containerPath.toOSString(); > if (reuseExistingFile) { >- File indexFile = new File(indexLocation); >+ File indexFile = getIndexFile(indexLocation); > if (indexFile.exists()) { // check before creating index so as to avoid creating a new empty index if file is missing > try { >- index = new Index(indexLocation, containerPathString, true /*reuse index file*/); >+ index = new Index(indexFile, containerPathString, true /*reuse index file*/); > indexes.put(indexLocation, index); > return index; > } catch (IOException e) { >@@ -250,7 +249,7 @@ > try { > if (VERBOSE) > Util.verbose("-> create empty index: "+indexLocation+" path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ >- index = new Index(indexLocation, containerPathString, false /*do not reuse index file*/); >+ index = new Index(getIndexFile(indexLocation), containerPathString, false /*do not reuse index file*/); > indexes.put(indexLocation, index); > return index; > } catch (IOException e) { >@@ -267,6 +266,11 @@ > public synchronized Index getIndex(String indexLocation) { > return (Index) indexes.get(indexLocation); // is null if unknown, call if the containerPath must be computed > } >+private File getIndexFile(String indexLocation) { >+ return (indexLocation.indexOf(File.separatorChar) < 0) >+ ? new File(this.indexesDirectory, indexLocation) >+ : new File(indexLocation); >+} > public synchronized Index getIndexForUpdate(IPath containerPath, boolean reuseExistingFile, boolean createIfMissing) { > String indexLocation = computeIndexLocation(containerPath); > if (getIndexStates().get(indexLocation) == REBUILDING_STATE) >@@ -281,20 +285,28 @@ > char[] savedIndexNames = readIndexState(); > if (savedIndexNames.length > 0) { > char[][] names = CharOperation.splitOn('\n', savedIndexNames); >- if (names.length > 0) { >- // check to see if workspace has moved, if so then do not trust saved indexes >- File indexesDirectory = new File(getJavaPluginWorkingLocation().toOSString()); >- char[] dirName = indexesDirectory.getAbsolutePath().toCharArray(); >- int delimiterPos = dirName.length; >- if (CharOperation.match(names[0], 0, delimiterPos, dirName, 0, delimiterPos, true)) { >- for (int i = 0, l = names.length; i < l; i++) { >+ int length = names.length; >+ if (length > 0) { >+ // First line should be DiskIndex signature, otherwise saved names are obsolete >+ if (length > 2 && names[0][0] == DiskIndex.SIGNATURE_ARRAY[0] && CharOperation.equals(names[0], DiskIndex.SIGNATURE_ARRAY)) { >+ // check to see if workspace has moved, if so then do not trust saved indexes >+ char[] dirName = getIndexesDirectory().getAbsolutePath().toCharArray(); >+ boolean sameDir = names[1][0] == dirName[0] && CharOperation.equals(names[1], dirName); // second line is indexes directory where existing index files were built >+ for (int i = 2; i < length; i++) { > char[] name = names[i]; >- if (name.length > 0) >- this.indexStates.put(new String(name), SAVED_STATE); >+ if (name.length > 0) { >+ if (CharOperation.indexOf(File.separatorChar, name) < 0) { >+ if (sameDir) { >+ this.indexStates.put(new String(name), SAVED_STATE); >+ } >+ } else { >+ this.indexStates.put(new String(name), SAVED_STATE); >+ } >+ } > } > } else { > savedIndexNamesFile.delete(); // forget saved indexes & delete each index file >- File[] files = indexesDirectory.listFiles(); >+ File[] files = getIndexesDirectory().listFiles(); > if (files != null) { > for (int i = 0, l = files.length; i < l; i++) { > String fileName = files[i].getAbsolutePath(); >@@ -310,11 +322,11 @@ > } > return this.indexStates; > } >-private IPath getJavaPluginWorkingLocation() { >- if (this.javaPluginLocation != null) return this.javaPluginLocation; >- >- IPath stateLocation = JavaCore.getPlugin().getStateLocation(); >- return this.javaPluginLocation = stateLocation; >+private File getIndexesDirectory() { >+ if (this.indexesDirectory == null) { >+ this.indexesDirectory = JavaCore.getPlugin().getStateLocation().toFile(); >+ } >+ return this.indexesDirectory; > } > public void indexDocument(SearchDocument searchDocument, SearchParticipant searchParticipant, Index index, IPath indexLocation) { > try { >@@ -365,8 +377,8 @@ > IndexRequest request = null; > if (target instanceof IFile) { > request = new AddJarFileToIndex((IFile) target, this); >- } else if (target instanceof java.io.File) { >- if (((java.io.File) target).isFile()) { >+ } else if (target instanceof File) { >+ if (((File) target).isFile()) { > request = new AddJarFileToIndex(path, this); > } else { > return; >@@ -443,7 +455,7 @@ > request = new IndexBinaryFolder((IFolder) target, this); > } else if (target instanceof IFile) { > request = new AddJarFileToIndex((IFile) target, this); >- } else if (target instanceof java.io.File) { >+ } else if (target instanceof File) { > request = new AddJarFileToIndex(containerPath, this); > } > if (request != null) >@@ -466,7 +478,7 @@ > > if (VERBOSE) > Util.verbose("-> recreating index: "+indexLocation+" for path: "+containerPathString); //$NON-NLS-1$ //$NON-NLS-2$ >- index = new Index(indexLocation, containerPathString, false /*reuse index file*/); >+ index = new Index(getIndexFile(indexLocation), containerPathString, false /*reuse index file*/); > this.indexes.put(indexLocation, index); > index.monitor = monitor; > return index; >@@ -494,7 +506,7 @@ > if (VERBOSE) > Util.verbose("removing index " + containerPath); //$NON-NLS-1$ > String indexLocation = computeIndexLocation(containerPath); >- File indexFile = new File(indexLocation); >+ File indexFile = getIndexFile(indexLocation); > if (indexFile.exists()) > indexFile.delete(); > Object o = this.indexes.get(indexLocation); >@@ -521,7 +533,7 @@ > if (index != null) index.monitor = null; > if (locations == null) locations = new String[max]; > locations[ptr++] = indexLocation; >- File indexFile = new File(indexLocation); >+ File indexFile = getIndexFile(indexLocation); > if (indexFile.exists()) { > indexFile.delete(); > } >@@ -579,7 +591,7 @@ > this.indexStates = null; > } > this.indexLocations = new SimpleLookupTable(); >- this.javaPluginLocation = null; >+ this.indexesDirectory = null; > } > public void saveIndex(Index index) throws IOException { > // must have permission to write from the write monitor >@@ -588,8 +600,7 @@ > Util.verbose("-> saving index " + index.getIndexFile()); //$NON-NLS-1$ > index.save(); > } >- // TODO should use getJavaPluginWorkingLocation()+index simple name to avoid bugs such as https://bugs.eclipse.org/bugs/show_bug.cgi?id=62267 >- String indexLocation = index.getIndexFile().getPath(); >+ String indexLocation = index.getIndexFile().getName(); > if (this.jobEnd > this.jobStart) { > Object containerPath = this.indexLocations.keyForValue(indexLocation); > if (containerPath != null) { >@@ -737,6 +748,10 @@ > BufferedWriter writer = null; > try { > writer = new BufferedWriter(new FileWriter(savedIndexNamesFile)); >+ writer.write(DiskIndex.SIGNATURE); >+ writer.write('\n'); >+ writer.write(getIndexesDirectory().getAbsolutePath()); >+ writer.write('\n'); > Object[] keys = indexStates.keyTable; > Object[] states = indexStates.valueTable; > for (int i = 0, l = states.length; i < l; i++) { >Index: compiler/org/eclipse/jdt/internal/compiler/util/SimpleSetOfCharArray.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/compiler/org/eclipse/jdt/internal/compiler/util/SimpleSetOfCharArray.java,v >retrieving revision 1.1 >diff -u -r1.1 SimpleSetOfCharArray.java >--- compiler/org/eclipse/jdt/internal/compiler/util/SimpleSetOfCharArray.java 3 Nov 2006 12:52:17 -0000 1.1 >+++ compiler/org/eclipse/jdt/internal/compiler/util/SimpleSetOfCharArray.java 22 Jan 2007 11:37:59 -0000 >@@ -76,6 +76,21 @@ > return result; > } > >+public char[] get(char[] object) { >+ int length = this.values.length; >+ int index = (CharOperation.hashCode(object) & 0x7FFFFFFF) % length; >+ char[] current; >+ while ((current = this.values[index]) != null) { >+ if (CharOperation.equals(current, object)) return current; >+ if (++index == length) index = 0; >+ } >+ this.values[index] = object; >+ >+ // assumes the threshold is never equal to the size of the table >+ if (++this.elementSize > this.threshold) rehash(); >+ return object; >+} >+ > public boolean includes(char[] object) { > int length = values.length; > int index = (CharOperation.hashCode(object) & 0x7FFFFFFF) % length;
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 138309
:
39391
|
39392
|
39393
|
57098
|
57246
|
57377