Merge "Remove unnecessary note fanout when removing notes"
This commit is contained in:
commit
f638679797
|
@ -158,6 +158,33 @@ public void remove() {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
int estimateSize(AnyObjectId noteOn, ObjectReader or) throws IOException {
|
||||
// If most of this fan-out is full, estimate it should still be split.
|
||||
if (LeafBucket.MAX_SIZE * 3 / 4 <= cnt)
|
||||
return 1 + LeafBucket.MAX_SIZE;
|
||||
|
||||
// Due to the uniform distribution of ObjectIds, having less nodes full
|
||||
// indicates a good chance the total number of children below here
|
||||
// is less than the MAX_SIZE split point. Get a more accurate count.
|
||||
|
||||
MutableObjectId id = new MutableObjectId();
|
||||
id.fromObjectId(noteOn);
|
||||
|
||||
int sz = 0;
|
||||
for (int cell = 0; cell < 256; cell++) {
|
||||
NoteBucket b = table[cell];
|
||||
if (b == null)
|
||||
continue;
|
||||
|
||||
id.setByte(prefixLen >> 1, cell);
|
||||
sz += b.estimateSize(id, or);
|
||||
if (LeafBucket.MAX_SIZE < sz)
|
||||
break;
|
||||
}
|
||||
return sz;
|
||||
}
|
||||
|
||||
@Override
|
||||
InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
|
||||
ObjectReader or) throws IOException {
|
||||
|
@ -182,6 +209,15 @@ InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
|
|||
if (cnt == 0)
|
||||
return null;
|
||||
|
||||
if (estimateSize(noteOn, or) < LeafBucket.MAX_SIZE) {
|
||||
// We are small enough to just contract to a single leaf.
|
||||
InMemoryNoteBucket r = new LeafBucket(prefixLen);
|
||||
for (Iterator<Note> i = iterator(noteOn, or); i.hasNext();)
|
||||
r = r.append(i.next());
|
||||
r.nonNotes = nonNotes;
|
||||
return r;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
} else if (n != b) {
|
||||
|
@ -268,6 +304,11 @@ Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader)
|
|||
return load(objId, reader).iterator(objId, reader);
|
||||
}
|
||||
|
||||
@Override
|
||||
int estimateSize(AnyObjectId objId, ObjectReader or) throws IOException {
|
||||
return load(objId, or).estimateSize(objId, or);
|
||||
}
|
||||
|
||||
@Override
|
||||
InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
|
||||
ObjectReader or) throws IOException {
|
||||
|
|
|
@ -129,6 +129,11 @@ public void remove() {
|
|||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
int estimateSize(AnyObjectId noteOn, ObjectReader or) throws IOException {
|
||||
return cnt;
|
||||
}
|
||||
|
||||
InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
|
||||
ObjectReader or) throws IOException {
|
||||
int p = search(noteOn);
|
||||
|
|
|
@ -64,6 +64,9 @@ abstract ObjectId get(AnyObjectId objId, ObjectReader reader)
|
|||
abstract Iterator<Note> iterator(AnyObjectId objId, ObjectReader reader)
|
||||
throws IOException;
|
||||
|
||||
abstract int estimateSize(AnyObjectId noteOn, ObjectReader or)
|
||||
throws IOException;
|
||||
|
||||
abstract InMemoryNoteBucket set(AnyObjectId noteOn, AnyObjectId noteData,
|
||||
ObjectReader reader) throws IOException;
|
||||
|
||||
|
|
Loading…
Reference in New Issue