Reapply "[#972] Use min/max builtins"

This reverts commit dad56d2e98.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-04-10 14:16:18 +03:00 committed by Evgenii Stratonikov
parent d864945961
commit 3dc81cb4fc
10 changed files with 11 additions and 53 deletions

View file

@ -100,10 +100,7 @@ func registerCandidates(c *helper.InitializeContext) error {
// Register candidates in batches in order to overcome the signers amount limit. // Register candidates in batches in order to overcome the signers amount limit.
// See: https://github.com/nspcc-dev/neo-go/blob/master/pkg/core/transaction/transaction.go#L27 // See: https://github.com/nspcc-dev/neo-go/blob/master/pkg/core/transaction/transaction.go#L27
for i := 0; i < need; i += registerBatchSize { for i := 0; i < need; i += registerBatchSize {
start, end := i, i+registerBatchSize start, end := i, min(i+registerBatchSize, need)
if end > need {
end = need
}
// This check is sound because transactions are accepted/rejected atomically. // This check is sound because transactions are accepted/rejected atomically.
if have >= end { if have >= end {
continue continue

View file

@ -82,10 +82,7 @@ func (c *cleanupTable) touch(keyString string, now uint64, binNodeInfo []byte) b
result := !ok || access.removeFlag || !bytes.Equal(access.binNodeInfo, binNodeInfo) result := !ok || access.removeFlag || !bytes.Equal(access.binNodeInfo, binNodeInfo)
access.removeFlag = false // reset remove flag on each touch access.removeFlag = false // reset remove flag on each touch
if now > access.epoch { access.epoch = max(access.epoch, now)
access.epoch = now
}
access.binNodeInfo = binNodeInfo // update binary node info access.binNodeInfo = binNodeInfo // update binary node info
c.lastAccess[keyString] = access c.lastAccess[keyString] = access

View file

@ -57,14 +57,6 @@ func (b *Blobovnicza) iterateBounds(useObjLimitBound bool, f func(uint64, uint64
return nil return nil
} }
func max(a, b uint64) uint64 {
if a > b {
return a
}
return b
}
// IterationElement represents a unit of elements through which Iterate operation passes. // IterationElement represents a unit of elements through which Iterate operation passes.
type IterationElement struct { type IterationElement struct {
addr oid.Address addr oid.Address

View file

@ -134,10 +134,7 @@ func (e *StorageEngine) ListWithCursor(ctx context.Context, prm ListWithCursorPr
continue continue
} }
count := prm.count - uint32(len(result)) count := min(prm.count-uint32(len(result)), batchSize)
if count > batchSize {
count = batchSize
}
var shardPrm shard.ListWithCursorPrm var shardPrm shard.ListWithCursorPrm
shardPrm.WithCount(count) shardPrm.WithCount(count)

View file

@ -343,16 +343,8 @@ func (s *Shard) removeGarbage(pctx context.Context) (result gcRunResult) {
} }
func (s *Shard) getExpiredObjectsParameters() (workerCount, batchSize int) { func (s *Shard) getExpiredObjectsParameters() (workerCount, batchSize int) {
workerCount = minExpiredWorkers workerCount = max(minExpiredWorkers, s.gc.gcCfg.expiredCollectorWorkerCount)
batchSize = minExpiredBatchSize batchSize = max(minExpiredBatchSize, s.gc.gcCfg.expiredCollectorBatchSize)
if s.gc.gcCfg.expiredCollectorBatchSize > batchSize {
batchSize = s.gc.gcCfg.expiredCollectorBatchSize
}
if s.gc.gcCfg.expiredCollectorWorkerCount > workerCount {
workerCount = s.gc.gcCfg.expiredCollectorWorkerCount
}
return return
} }

View file

@ -162,11 +162,7 @@ func (c *Client) DepositNotary(amount fixedn.Fixed8, delta uint32) (res util.Uin
return util.Uint256{}, fmt.Errorf("can't get previous expiration value: %w", err) return util.Uint256{}, fmt.Errorf("can't get previous expiration value: %w", err)
} }
till := int64(bc + delta) till := max(int64(bc+delta), currentTill)
if till < currentTill {
till = currentTill
}
return c.depositNotary(amount, till) return c.depositNotary(amount, till)
} }

View file

@ -343,10 +343,7 @@ func PayloadRange(ctx context.Context, prm PayloadRangePrm) (*PayloadRangeRes, e
return nil, new(apistatus.ObjectOutOfRange) return nil, new(apistatus.ObjectOutOfRange)
} }
ln := prm.ln ln := min(prm.ln, maxInitialBufferSize)
if ln > maxInitialBufferSize {
ln = maxInitialBufferSize
}
w := bytes.NewBuffer(make([]byte, 0, ln)) w := bytes.NewBuffer(make([]byte, 0, ln))
_, err = io.CopyN(w, rdr, int64(prm.ln)) _, err = io.CopyN(w, rdr, int64(prm.ln))

View file

@ -164,10 +164,7 @@ func (s *searchStreamMsgSizeCtrl) Send(resp *object.SearchResponse) error {
newResp.SetBody(body) newResp.SetBody(body)
} }
cut := s.addrAmount cut := min(s.addrAmount, ln)
if cut > ln {
cut = ln
}
body.SetIDList(ids[:cut]) body.SetIDList(ids[:cut])
newResp.SetMetaHeader(resp.GetMetaHeader()) newResp.SetMetaHeader(resp.GetMetaHeader())

View file

@ -388,10 +388,7 @@ func (it *sliceKeySpaceIterator) Next(_ context.Context, size uint32) ([]objectc
if it.cur >= len(it.objs) { if it.cur >= len(it.objs) {
return nil, engine.ErrEndOfListing return nil, engine.ErrEndOfListing
} }
end := it.cur + int(size) end := min(it.cur+int(size), len(it.objs))
if end > len(it.objs) {
end = len(it.objs)
}
ret := it.objs[it.cur:end] ret := it.objs[it.cur:end]
it.cur = end it.cur = end
return ret, nil return ret, nil

View file

@ -167,9 +167,7 @@ func mergeOperationStreams(streams []chan *pilorama.Move, merged chan<- *piloram
merged <- ms[minTimeMoveIndex] merged <- ms[minTimeMoveIndex]
height := ms[minTimeMoveIndex].Time height := ms[minTimeMoveIndex].Time
if ms[minTimeMoveIndex] = <-streams[minTimeMoveIndex]; ms[minTimeMoveIndex] == nil { if ms[minTimeMoveIndex] = <-streams[minTimeMoveIndex]; ms[minTimeMoveIndex] == nil {
if minStreamedLastHeight > height { minStreamedLastHeight = min(minStreamedLastHeight, height)
minStreamedLastHeight = height
}
} }
} }
@ -203,9 +201,7 @@ func (s *Service) applyOperationStream(ctx context.Context, cid cid.ID, treeID s
errGroup.Go(func() error { errGroup.Go(func() error {
if err := s.forest.TreeApply(ctx, cid, treeID, m, true); err != nil { if err := s.forest.TreeApply(ctx, cid, treeID, m, true); err != nil {
heightMtx.Lock() heightMtx.Lock()
if m.Time < unappliedOperationHeight { unappliedOperationHeight = min(unappliedOperationHeight, m.Time)
unappliedOperationHeight = m.Time
}
heightMtx.Unlock() heightMtx.Unlock()
return err return err
} }