[#19] transformer: Make writeChunk non-recursive

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2023-02-18 10:36:20 +03:00 committed by Gitea
parent 1c94309d7a
commit b696d3c70e

View file

@ -229,6 +229,7 @@ func (s *payloadSizeLimiter) initializeLinking(parHdr *object.Object) {
} }
func (s *payloadSizeLimiter) writeChunk(chunk []byte) error { func (s *payloadSizeLimiter) writeChunk(chunk []byte) error {
for {
// statement is true if the previous write of bytes reached exactly the boundary. // statement is true if the previous write of bytes reached exactly the boundary.
if s.written > 0 && s.written%s.maxSize == 0 { if s.written > 0 && s.written%s.maxSize == 0 {
if s.written == s.maxSize { if s.written == s.maxSize {
@ -262,13 +263,13 @@ func (s *payloadSizeLimiter) writeChunk(chunk []byte) error {
// increase written bytes counter // increase written bytes counter
s.written += cut s.written += cut
// if there are more bytes in buffer we call method again to start filling another object if cut == ln {
if ln > leftToEdge {
return s.writeChunk(chunk[cut:])
}
return nil return nil
} }
// if there are more bytes in buffer we call method again to start filling another object
chunk = chunk[cut:]
}
}
func (s *payloadSizeLimiter) prepareFirstChild() { func (s *payloadSizeLimiter) prepareFirstChild() {
// initialize split header with split ID on first object in chain // initialize split header with split ID on first object in chain