### Eclipse Workspace Patch 1.0 #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.69 diff -u -r1.69 DiskIndex.java --- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 9 Mar 2010 05:55:04 -0000 1.69 +++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 19 Apr 2010 06:07:34 -0000 @@ -132,11 +132,11 @@ } return results; } -private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, CategoryTable wordsToDocNumbers, MemoryIndex memoryIndex) throws IOException { +private HashtableOfObject addQueryResult(HashtableOfObject results, char[] word, CategoryTable wordsToDocNumbers, MemoryIndex memoryIndex, boolean checkBeforeAdd) 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 = (EntryResult) results.get(word); + EntryResult result = checkBeforeAdd ? (EntryResult) results.get(word) : null; if (memoryIndex == null) { if (result == null) results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); @@ -161,6 +161,10 @@ if (this.categoryOffsets == null) return null; // file is empty HashtableOfObject results = null; // initialized if needed + + // No need to check the results table for duplicacy while processing the + // first category table or if the first category tables doesn't have any results. + boolean checkBeforeAdd = 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 @@ -168,9 +172,11 @@ char[][] words = wordsToDocNumbers.keyTable; if (results == null) results = new HashtableOfObject(wordsToDocNumbers.elementSize); - for (int j = 0, m = words.length; j < m; j++) + for (int j = 0, m = words.length; j < m; j++) { if (words[j] != null) - results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex); + results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex, checkBeforeAdd); + } + checkBeforeAdd = true; } } if (results != null && this.cachedChunks == null) @@ -180,8 +186,10 @@ 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); + if (wordsToDocNumbers != null && wordsToDocNumbers.containsKey(key)) { + results = addQueryResult(results, key, wordsToDocNumbers, memoryIndex, checkBeforeAdd); + checkBeforeAdd = true; + } } break; case SearchPattern.R_PREFIX_MATCH | SearchPattern.R_CASE_SENSITIVE: @@ -192,8 +200,9 @@ 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); + results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, checkBeforeAdd); } + checkBeforeAdd = true; } } break; @@ -205,8 +214,9 @@ 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); + results = addQueryResult(results, word, wordsToDocNumbers, memoryIndex, checkBeforeAdd); } + checkBeforeAdd = true; } } }