Implemented data coalescing in sprout->shrub conversion

Note we still end up with a shrub, even if the file could revert back to
a sprout. This is just a simplification for the inlined file logic. We
never implicitly revert to a sprout.
This commit is contained in:
Christopher Haster
2023-10-09 12:26:03 -05:00
parent e43b4c7d9a
commit addaa8fe3e
+47 -10
View File
@@ -9219,6 +9219,21 @@ static int lfsr_file_carveinlined(lfs_t *lfs, lfsr_file_t *file,
// left data? this may create a hole
if (pos > 0) {
// can coalesce?
if (lfsr_data_size(&file->inlined.u.data) >= pos
&& pos+weight+delta <= lfs->cfg->coalesce_size) {
scratch_datas[0] = LFSR_DATA_DISK(
file->inlined.u.data.u.disk.block,
file->inlined.u.data.u.disk.off,
pos);
scratch_datas[1] = data;
datas_ = &scratch_datas[2];
data = lfsr_data_fromcat(&scratch_datas[0], 2);
weight += pos;
pos = 0;
// need to carve
} else {
*attrs_++ = LFSR_ATTR(0,
SHRUB(INLINED), +pos, DISK(
file->inlined.u.data.u.disk.block,
@@ -9231,18 +9246,31 @@ static int lfsr_file_carveinlined(lfs_t *lfs, lfsr_file_t *file,
lfsr_data_size(&file->inlined.u.data),
pos);
}
// append our data
if (weight + delta > 0) {
*attrs_++ = LFSR_ATTR(pos,
SHRUB(INLINED), +weight + delta, DATA(data));
estimate += LFSR_ATTR_ESTIMATE
+ lfsr_data_size(&data);
}
// right data?
// right data? this may also create a hole if delta > 0
if (lfsr_data_size(&file->inlined.u.data) > pos + weight) {
*attrs_++ = LFSR_ATTR(pos + weight + delta,
// can coalesce?
if (lfsr_data_size(&data) == weight + delta
&& lfsr_data_size(&data)
+ lfsr_data_size(&file->inlined.u.data)
- (pos + weight)
<= lfs->cfg->coalesce_size) {
*datas_++ = LFSR_DATA_DISK(
file->inlined.u.data.u.disk.block,
file->inlined.u.data.u.disk.off
+ (pos + weight),
lfsr_data_size(&file->inlined.u.data)
- (pos + weight));
data = lfsr_data_fromcat(
scratch_datas,
datas_ - scratch_datas);
weight += lfsr_data_size(&file->inlined.u.data)
- (pos + weight);
// need to carve
} else {
*attrs_++ = LFSR_ATTR(pos,
SHRUB(INLINED), +lfsr_data_size(&file->inlined.u.data)
- (pos + weight),
DISK(
@@ -9255,6 +9283,15 @@ static int lfsr_file_carveinlined(lfs_t *lfs, lfsr_file_t *file,
+ lfsr_data_size(&file->inlined.u.data)
- (pos + weight);
}
}
// append our data
if (weight + delta > 0) {
*attrs_++ = LFSR_ATTR(pos,
SHRUB(INLINED), +weight + delta, DATA(data));
estimate += LFSR_ATTR_ESTIMATE
+ lfsr_data_size(&data);
}
// have a shrub?
} else {
@@ -9305,8 +9342,8 @@ static int lfsr_file_carveinlined(lfs_t *lfs, lfsr_file_t *file,
scratch_datas[1] = data;
datas_ = &scratch_datas[2];
data = lfsr_data_fromcat(&scratch_datas[0], 2);
pos = left_rid-(left_weight-1);
weight += left_weight - left_overlap;
pos = left_rid-(left_weight-1);
left_overlap = 0;
// need to carve out left data?