lib/storage: simplify code a bit after 3f5959c053

This commit is contained in:
Aliaksandr Valialkin 2022-10-21 14:39:27 +03:00
parent 1fb2be0cae
commit 2f8861ed9c
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1

View file

@ -476,17 +476,13 @@ func (rrs *rawRowsShard) addRows(pt *partition, rows []rawRow) {
n := getMaxRawRowsPerShard() n := getMaxRawRowsPerShard()
rrs.rows = make([]rawRow, 0, n) rrs.rows = make([]rawRow, 0, n)
} }
maxRowsCount := cap(rrs.rows) n := copy(rrs.rows[len(rrs.rows):cap(rrs.rows)], rows)
capacity := maxRowsCount - len(rrs.rows) rrs.rows = rrs.rows[:len(rrs.rows)+n]
if capacity >= len(rows) { rows = rows[n:]
// Fast path - rows fit rrs.rows capacity. if len(rows) > 0 {
rrs.rows = append(rrs.rows, rows...) // Slow path - rows did't fit rrs.rows capacity.
} else { // Convert rrs.rows to rowsToFlush and convert it to a part,
// Slow path - rows don't fit rrs.rows capacity. // then try moving the remaining rows to rrs.rows.
// Fill rrs.rows with rows until capacity,
// then put rrs.rows to rowsToFlush and convert it to a part.
n := copy(rrs.rows[:cap(rrs.rows)], rows)
rows = rows[n:]
rowsToFlush = rrs.rows rowsToFlush = rrs.rows
n = getMaxRawRowsPerShard() n = getMaxRawRowsPerShard()
rrs.rows = make([]rawRow, 0, n) rrs.rows = make([]rawRow, 0, n)