Skip to content

Commit 19a857a

Browse files
committed
PR feedback: start/endBlock() helpers
1 parent 779e033 commit 19a857a

File tree

1 file changed

+10
-7
lines changed
  • packages/orchestrator/pkg/sandbox/block

1 file changed

+10
-7
lines changed

packages/orchestrator/pkg/sandbox/block/cache.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,27 +248,30 @@ func (c *Cache) Slice(off, length int64) ([]byte, error) {
248248
return nil, BytesNotAvailableError{}
249249
}
250250

251+
func (c *Cache) startBlock(off int64) uint {
252+
return uint(off / c.blockSize)
253+
}
254+
255+
func (c *Cache) endBlock(off int64) uint {
256+
return uint((off + c.blockSize - 1) / c.blockSize)
257+
}
258+
251259
func (c *Cache) isCached(off, length int64) bool {
252260
if off >= c.size {
253261
return false
254262
}
255263

256264
end := min(off+length, c.size)
257-
start := uint(off / c.blockSize)
258-
endBlock := uint((end + c.blockSize - 1) / c.blockSize)
259265

260-
return c.dirty.HasRange(start, endBlock)
266+
return c.dirty.HasRange(c.startBlock(off), c.endBlock(end))
261267
}
262268

263269
func (c *Cache) setIsCached(off, length int64) {
264270
if length <= 0 {
265271
return
266272
}
267273

268-
start := uint(off / c.blockSize)
269-
endBlock := uint((off + length + c.blockSize - 1) / c.blockSize)
270-
271-
c.dirty.SetRange(start, endBlock)
274+
c.dirty.SetRange(c.startBlock(off), c.endBlock(off+length))
272275
}
273276

274277
// When using WriteAtWithoutLock you must ensure thread safety, ideally by only writing to the same block once and the exposing the slice.

0 commit comments

Comments
 (0)