### 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.56 diff -u -r1.56 DiskIndex.java --- search/org/eclipse/jdt/internal/core/index/DiskIndex.java 20 Feb 2007 12:01:28 -0000 1.56 +++ search/org/eclipse/jdt/internal/core/index/DiskIndex.java 21 Feb 2007 18:59:22 -0000 @@ -142,8 +142,8 @@ result.addDocumentTable(wordsToDocNumbers); } else { SimpleLookupTable docsToRefs = memoryIndex.docsToReferences; - if (result == null) - result = new EntryResult(word, null); + if (result == null) result = new EntryResult(word, null); + this.streamEnd = -1; // unknown int[] docNumbers = readDocumentNumbers(wordsToDocNumbers.get(word)); for (int i = 0, l = docNumbers.length; i < l; i++) { String docName = readDocumentName(docNumbers[i]); @@ -769,7 +769,6 @@ stream.skip(offset); this.streamBuffer = new byte[BUFFER_READ_SIZE]; this.bufferIndex = 0; - this.streamEnd = -1; // unknown this.streamPos = stream.read(this.streamBuffer, 0, BUFFER_READ_SIZE) + offset; return readStreamDocumentArray(stream, readStreamInt(stream)); } finally { @@ -943,30 +942,31 @@ indexes[i] = streamBuffer[idx++] & 0xFF; } } else { - int i = 0; - while (idx < bufferSize) { - indexes[i++] = streamBuffer[idx++] & 0xFF; - } - this.bufferIndex -= bufferSize; + // set size to read on file int readSize = this.streamEnd == -1 ? BUFFER_READ_SIZE : this.streamEnd - this.streamPos; if (readSize > bufferSize) readSize = bufferSize; - this.streamPos += stream.read(this.streamBuffer, 0, bufferSize); - idx = 0; - while (idx < this.bufferIndex) { - indexes[i++] = streamBuffer[idx++] & 0xFF; + // fill indexes array + for (int i = 0; i < arraySize; i++) { + indexes[i] = streamBuffer[idx++] & 0xFF; + if (idx == bufferSize) { + this.streamPos += stream.read(this.streamBuffer, 0, readSize); + idx = 0; + } } } break; case 2 : - this.bufferIndex += arraySize << 1; + this.bufferIndex += (arraySize << 1); if (this.bufferIndex < bufferSize) { for (int i = 0; i < arraySize; i++) { int val = (streamBuffer[idx++]&0xFF)<<8; indexes[i] = val + (streamBuffer[idx++] & 0xFF); } } else { + // set size to read on file int readSize = this.streamEnd == -1 ? BUFFER_READ_SIZE : this.streamEnd - this.streamPos; if (readSize > bufferSize) readSize = bufferSize; + // fill indexes array for (int i = 0; i < arraySize; i++) { int val = (streamBuffer[idx++]&0xFF)<<8; if (idx == bufferSize) { @@ -979,11 +979,10 @@ idx = 0; } } - this.bufferIndex -= bufferSize; } break; default : - this.bufferIndex += arraySize << 2; + this.bufferIndex += (arraySize << 2); if (this.bufferIndex < bufferSize) { for (int i = 0; i < arraySize; i++) { int val = (streamBuffer[idx++]&0xFF)<<24; @@ -992,8 +991,10 @@ indexes[i] += val + (streamBuffer[idx++]&0xFF); } } else { + // set size to read on file int readSize = this.streamEnd == -1 ? BUFFER_READ_SIZE : this.streamEnd - this.streamPos; if (readSize > bufferSize) readSize = bufferSize; + // fill indexes array for (int i = 0; i < arraySize; i++) { int val = (streamBuffer[idx++]&0xFF)<<24; if (idx == bufferSize) { @@ -1016,10 +1017,10 @@ idx = 0; } } - this.bufferIndex -= bufferSize; } break; } + this.bufferIndex = idx; // rsync buffer index return indexes; } private int readStreamInt(FileInputStream stream) throws IOException {