1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-05 15:25:49 +02:00

Got rid of the caching of Chunks for now. The databases aren't too large yet and this makes Mozilla indexing 10% faster.

This commit is contained in:
Doug Schaefer 2006-05-05 17:44:37 +00:00
parent 918b130a5b
commit 4a257e3fea
2 changed files with 0 additions and 45 deletions

View file

@ -28,8 +28,6 @@ public class Chunk {
// Cache info
private Database db;
int index;
private Chunk prevChunk;
private Chunk nextChunk;
Chunk(RandomAccessFile file, int offset) throws CoreException {
try {
@ -64,32 +62,13 @@ public class Chunk {
return buffer.getChar(offset % Database.CHUNK_SIZE);
}
Chunk getNextChunk() {
return nextChunk;
}
void setNextChunk(Chunk nextChunk) {
this.nextChunk = nextChunk;
}
Chunk getPrevChunk() {
return prevChunk;
}
void setPrevChunk(Chunk prevChunk) {
this.prevChunk = prevChunk;
}
void clear(int offset, int length) {
buffer.position(offset % Database.CHUNK_SIZE);
buffer.put(new byte[length]);
}
void free() {
// nextChunk should be null
db.toc[index] = null;
db.lruChunk = prevChunk;
prevChunk.nextChunk = null;
}
}

View file

@ -26,15 +26,10 @@ public class Database {
private final RandomAccessFile file;
Chunk[] toc;
Chunk mruChunk;
Chunk lruChunk;
private int loadedChunks;
// public for tests only, you shouldn't need these
public static final int VERSION_OFFSET = 0;
public static final int CHUNK_SIZE = 4096;
public static final int CACHE_SIZE = 10000; // Should be configable
public static final int MIN_SIZE = 16;
public static final int INT_SIZE = 4;
public static final int CHAR_SIZE = 2;
@ -106,28 +101,9 @@ public class Database {
int index = offset / CHUNK_SIZE;
Chunk chunk = toc[index];
if (chunk == null) {
if (loadedChunks == CACHE_SIZE)
// cache is full, free lruChunk
lruChunk.free();
chunk = toc[index] = new Chunk(file, index * CHUNK_SIZE);
}
// insert into cache
// TODO We can move this into the chunks
Chunk prevChunk = chunk.getPrevChunk();
Chunk nextChunk = chunk.getNextChunk();
if (prevChunk != null)
prevChunk.setNextChunk(nextChunk);
if (nextChunk != null)
nextChunk.setPrevChunk(prevChunk);
if (mruChunk != null) {
chunk.setNextChunk(mruChunk);
mruChunk.setPrevChunk(chunk);
}
mruChunk = chunk;
chunk.setPrevChunk(null);
return chunk;
}