[#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 return nil, nil, errParentAddressDiffers
} }
sz := head.PayloadSize() nextOffset := a.currentOffset - head.PayloadSize()
clampedFrom := max(from, nextOffset)
a.currentOffset -= sz clampedTo := min(to, a.currentOffset)
if clampedFrom < clampedTo {
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
}
index := len(rngs) index := len(rngs)
rngs = append(rngs, objectSDK.Range{}) rngs = append(rngs, objectSDK.Range{})
rngs[index].SetOffset(off) rngs[index].SetOffset(clampedFrom - nextOffset)
rngs[index].SetLength(sz) rngs[index].SetLength(clampedTo - clampedFrom)
id, _ := head.ID() id, _ := head.ID()
chain = append(chain, id) chain = append(chain, id)
} }
a.currentOffset = nextOffset
prevID, hasPrev = head.PreviousID() prevID, hasPrev = head.PreviousID()
} }