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 --- 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 15 Apr 2010 06:29:02 -0000 @@ -132,11 +132,13 @@ } 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 = null; + if (checkBeforeAdd) + result = (EntryResult) results.get(word); if (memoryIndex == null) { if (result == null) results.putUnsafely(word, new EntryResult(word, wordsToDocNumbers)); @@ -161,6 +163,7 @@ if (this.categoryOffsets == null) return null; // file is empty HashtableOfObject results = null; // initialized if needed + boolean checkBeforeAdd = memoryIndex != null; // used to optimize adding the results 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 @@ -170,7 +173,8 @@ 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); + results = addQueryResult(results, words[j], wordsToDocNumbers, memoryIndex, checkBeforeAdd); + checkBeforeAdd = true; } } if (results != null && this.cachedChunks == null) @@ -180,8 +184,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 +198,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 +212,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; } } }