### Eclipse Workspace Patch 1.0 #P org.eclipse.jdt.core Index: search/org/eclipse/jdt/internal/core/index/CategoryTable.java =================================================================== RCS file: search/org/eclipse/jdt/internal/core/index/CategoryTable.java diff -N search/org/eclipse/jdt/internal/core/index/CategoryTable.java --- search/org/eclipse/jdt/internal/core/index/CategoryTable.java 9 Mar 2010 05:55:03 -0000 1.1 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,76 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2010 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 - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package org.eclipse.jdt.internal.core.index; - -import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; - - -/** - * Hashtable of {char[] --> Object } typically used for the category table - * stored in the {@link DiskIndex disk index}. - *

- * This is a more specific {@link HashtableOfObject hashtable of objects} where - * the hash code is computed by using twice more characters than the hash - * code computation of the {@link HashtableOfObject original hashtable}. - *

- * This is typically important for type declaration category table for which the - * key postfix might have more than 16 identical characters... - *

- * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=289057" - */ -public final class CategoryTable extends HashtableOfObject { - - public CategoryTable() { - super(); - } - public CategoryTable(int size) { - super(size); - } - - /* (non-Javadoc) - * - * The hash code computation is done by using half of the 32 characters last - * characters of the given array instead of only half of the 16 last ones for the - * super implementation... - * - * @see org.eclipse.jdt.internal.compiler.util.HashtableOfObject#hashCode(char[]) - */ - protected int hashCode(char[] array) { - int length = array.length; - int hash = length == 0 ? 31 : array[0]; - if (length < 16) { - for (int i = length; --i > 0;) - hash = (hash * 31) + array[i]; - } else { - // 16 characters is enough to compute a decent hash code, don't waste time examining every character - for (int i = length - 1, last = i > 32 ? i - 32 : 0; i > last; i -= 2) - hash = (hash * 31) + array[i]; - - } - return hash & 0x7FFFFFFF; - - } - - /* (non-Javadoc) - * @see org.eclipse.jdt.internal.compiler.util.HashtableOfObject#rehash() - */ - protected void rehash() { - CategoryTable newHashtable = new CategoryTable(this.elementSize * 2); // double the number of expected elements - char[] currentKey; - for (int i = this.keyTable.length; --i >= 0;) - if ((currentKey = this.keyTable[i]) != null) - newHashtable.putUnsafely(currentKey, this.valueTable[i]); - - this.keyTable = newHashtable.keyTable; - this.valueTable = newHashtable.valueTable; - this.threshold = newHashtable.threshold; - } -} 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.70 diff -u -r1.70 DiskIndex.java --- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 20 Apr 2010 07:37:52 -0000 1.70 +++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 6 May 2010 06:22:55 -0000 @@ -132,20 +132,20 @@ } return results; } -private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, CategoryTable wordsToDocNumbers, MemoryIndex memoryIndex, boolean prevResults) throws IOException { +private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, Object docs, MemoryIndex memoryIndex, boolean prevResults) throws IOException { // must skip over documents which have been added/changed/deleted in the memory index if (results == null) results = new HashtableOfObject(13); EntryResult result = prevResults ? (EntryResult) results.get(word) : null; if (memoryIndex == null) { if (result == null) - results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); + results.putUnsafely(word, new EntryResult(word, docs)); else - result.addDocumentTable(wordsToDocNumbers); + result.addDocumentTable(docs); } else { SimpleLookupTable docsToRefs = memoryIndex.docsToReferences; if (result == null) result = new EntryResult(word, null); - int[] docNumbers = readDocumentNumbers(wordsToDocNumbers.get(word)); + int[] docNumbers = readDocumentNumbers(docs); for (int i = 0, l = docNumbers.length; i < l; i++) { String docName = readDocumentName(docNumbers[i]); if (!docsToRefs.containsKey(docName)) @@ -167,14 +167,15 @@ boolean prevResults = false; if (key == null) { for (int i = 0, l = categories.length; i < l; i++) { - CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match + HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], true); // cache if key is null since its a definite match if (wordsToDocNumbers != null) { char[][] words = wordsToDocNumbers.keyTable; + Object[] values = wordsToDocNumbers.valueTable; if (results == null) results = new HashtableOfObject(wordsToDocNumbers.elementSize); for (int j = 0, m = words.length; j < m; j++) if (words[j] != null) - results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex, prevResults); + results = addQueryResult(results, words[j], values[j], memoryIndex, prevResults); } prevResults = results != null; } @@ -184,21 +185,23 @@ switch (matchRule) { case SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE: for (int i = 0, l = categories.length; i < l; i++) { - CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); - if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) - results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex, prevResults); + HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); + Object value; + if (wordsToDocNumbers != null && (value = wordsToDocNumbers.get(key)) != null) + results = addQueryResult(results, key, value, memoryIndex, prevResults); prevResults = results != null; } break; case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: for (int i = 0, l = categories.length; i < l; i++) { - CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); + HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); if (wordsToDocNumbers != null) { char[][] words = wordsToDocNumbers.keyTable; + Object[] values = wordsToDocNumbers.valueTable; for (int j = 0, m = words.length; j < m; j++) { char[] word = words[j]; if (word != null && key[0] == word[0] && CharOperation.prefixEquals(key, word)) - results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, prevResults); + results = addQueryResult(results, word, values[j], memoryIndex, prevResults); } } prevResults = results != null; @@ -206,13 +209,14 @@ break; default: for (int i = 0, l = categories.length; i < l; i++) { - CategoryTable wordsToDocNumbers = readCategoryTable(categories[i], false); + HashtableOfObject wordsToDocNumbers = readCategoryTable(categories[i], false); if (wordsToDocNumbers != null) { char[][] words = wordsToDocNumbers.keyTable; + Object[] values = wordsToDocNumbers.valueTable; for (int j = 0, m = words.length; j < m; j++) { char[] word = words[j]; if (word != null && Index.isMatch(key, word, matchRule)) - results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, prevResults); + results = addQueryResult(results, word, values[j], memoryIndex, prevResults); } } prevResults = results != null; @@ -344,9 +348,9 @@ char[] categoryName = categoryNames[i]; if (categoryName != null) { SimpleWordSet wordSet = (SimpleWordSet) wordSets[i]; - CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); + HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); if (wordsToDocs == null) - this.categoryTables.put(categoryName, wordsToDocs = new CategoryTable(wordSet.elementSize)); + this.categoryTables.put(categoryName, wordsToDocs = new HashtableOfObject(wordSet.elementSize)); char[][] words = wordSet.words; for (int j = 0, m = words.length; j < m; j++) { @@ -450,11 +454,11 @@ this.categoryTables = null; } private void mergeCategory(char[] categoryName, DiskIndex onDisk, int[] positions, FileOutputStream stream) throws IOException { - CategoryTable wordsToDocs = (CategoryTable) this.categoryTables.get(categoryName); + HashtableOfObject wordsToDocs = (HashtableOfObject) this.categoryTables.get(categoryName); if (wordsToDocs == null) - wordsToDocs = new CategoryTable(3); + wordsToDocs = new HashtableOfObject(3); - CategoryTable oldWordsToDocs = onDisk.readCategoryTable(categoryName, true); + HashtableOfObject oldWordsToDocs = onDisk.readCategoryTable(categoryName, true); if (oldWordsToDocs != null) { char[][] oldWords = oldWordsToDocs.keyTable; Object[] oldArrayOffsets = oldWordsToDocs.valueTable; @@ -588,7 +592,7 @@ this.streamBuffer = null; } } -private synchronized CategoryTable readCategoryTable(char[] categoryName, boolean readDocNumbers) throws IOException { +private synchronized HashtableOfObject readCategoryTable(char[] categoryName, boolean readDocNumbers) throws IOException { // result will be null if categoryName is unknown int offset = this.categoryOffsets.get(categoryName); if (offset == HashtableOfIntValues.NO_VALUE) { @@ -598,7 +602,7 @@ if (this.categoryTables == null) { this.categoryTables = new HashtableOfObject(3); } else { - CategoryTable cachedTable = (CategoryTable) this.categoryTables.get(categoryName); + HashtableOfObject cachedTable = (HashtableOfObject) this.categoryTables.get(categoryName); if (cachedTable != null) { if (readDocNumbers) { // must cache remaining document number arrays Object[] arrayOffsets = cachedTable.valueTable; @@ -611,7 +615,7 @@ } FileInputStream stream = new FileInputStream(this.indexFile); - CategoryTable categoryTable = null; + HashtableOfObject categoryTable = null; char[][] matchingWords = null; int count = 0; int firstOffset = -1; @@ -629,7 +633,7 @@ System.err.println("size = "+size); //$NON-NLS-1$ System.err.println("-------------------- END --------------------"); //$NON-NLS-1$ } - categoryTable = new CategoryTable(size); + categoryTable = new HashtableOfObject(size); } catch (OutOfMemoryError oom) { // DEBUG oom.printStackTrace(); @@ -1038,10 +1042,10 @@ Object[] tables = this.categoryTables.valueTable; for (int i = 0, l = categoryNames.length; i < l; i++) if (categoryNames[i] != null) - writeCategoryTable(categoryNames[i], (CategoryTable) tables[i], stream); + writeCategoryTable(categoryNames[i], (HashtableOfObject) tables[i], stream); this.categoryTables = null; } -private void writeCategoryTable(char[] categoryName, CategoryTable wordsToDocs, FileOutputStream stream) throws IOException { +private void writeCategoryTable(char[] categoryName, HashtableOfObject wordsToDocs, FileOutputStream stream) throws IOException { // the format of a category table is as follows: // any document number arrays with >= 256 elements are written before the table (the offset to each array is remembered) // then the number of word->int[] pairs in the table is written Index: search/org/eclipse/jdt/internal/core/index/EntryResult.java =================================================================== RCS file: /cvsroot/eclipse/org.eclipse.jdt.core/search/org/eclipse/jdt/internal/core/index/EntryResult.java,v retrieving revision 1.13 diff -u -r1.13 EntryResult.java --- search/org/eclipse/jdt/internal/core/index/EntryResult.java 7 Mar 2009 01:08:11 -0000 1.13 +++ search/org/eclipse/jdt/internal/core/index/EntryResult.java 6 May 2010 06:22:55 -0000 @@ -11,32 +11,31 @@ package org.eclipse.jdt.internal.core.index; import org.eclipse.jdt.core.compiler.CharOperation; -import org.eclipse.jdt.internal.compiler.util.HashtableOfObject; import org.eclipse.jdt.internal.compiler.util.SimpleSet; public class EntryResult { private char[] word; -private HashtableOfObject[] documentTables; +private Object[] documentTables; private SimpleSet documentNames; -public EntryResult(char[] word, HashtableOfObject table) { +public EntryResult(char[] word, Object table) { this.word = word; if (table != null) - this.documentTables = new HashtableOfObject[] {table}; + this.documentTables = new Object[] {table}; } public void addDocumentName(String documentName) { if (this.documentNames == null) this.documentNames = new SimpleSet(3); this.documentNames.add(documentName); } -public void addDocumentTable(HashtableOfObject table) { +public void addDocumentTable(Object table) { if (this.documentTables != null) { int length = this.documentTables.length; - System.arraycopy(this.documentTables, 0, this.documentTables = new HashtableOfObject[length + 1], 0, length); + System.arraycopy(this.documentTables, 0, this.documentTables = new Object[length + 1], 0, length); this.documentTables[length] = table; } else { - this.documentTables = new HashtableOfObject[] {table}; + this.documentTables = new Object[] {table}; } } public char[] getWord() { @@ -46,7 +45,7 @@ if (this.documentTables != null) { int length = this.documentTables.length; if (length == 1 && this.documentNames == null) { // have a single table - Object offset = this.documentTables[0].get(this.word); + Object offset = this.documentTables[0]; int[] numbers = index.diskIndex.readDocumentNumbers(offset); String[] names = new String[numbers.length]; for (int i = 0, l = numbers.length; i < l; i++) @@ -55,7 +54,7 @@ } for (int i = 0; i < length; i++) { - Object offset = this.documentTables[i].get(this.word); + Object offset = this.documentTables[i]; int[] numbers = index.diskIndex.readDocumentNumbers(offset); for (int j = 0, k = numbers.length; j < k; j++) addDocumentName(index.diskIndex.readDocumentName(numbers[j]));