[#1616] getsvc: Simplify buildChainRange()

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2025-01-28 15:01:02 +03:00 committed by Evgenii Stratonikov
parent c8acdf40bb
commit b309b34bfc

View file

@ -70,30 +70,20 @@ func (a *assembler) buildChainRange(ctx context.Context, prevID oid.ID) ([]oid.I
return nil, nil, errParentAddressDiffers
}
sz := head.PayloadSize()
a.currentOffset -= sz
if a.currentOffset < to {
off := uint64(0)
if from > a.currentOffset {
off = from - a.currentOffset
sz -= from - a.currentOffset
}
if to < a.currentOffset+off+sz {
sz = to - off - a.currentOffset
}
nextOffset := a.currentOffset - head.PayloadSize()
clampedFrom := max(from, nextOffset)
clampedTo := min(to, a.currentOffset)
if clampedFrom < clampedTo {
index := len(rngs)
rngs = append(rngs, objectSDK.Range{})
rngs[index].SetOffset(off)
rngs[index].SetLength(sz)
rngs[index].SetOffset(clampedFrom - nextOffset)
rngs[index].SetLength(clampedTo - clampedFrom)
id, _ := head.ID()
chain = append(chain, id)
}
a.currentOffset = nextOffset
prevID, hasPrev = head.PreviousID()
}