Skip to content

Commit 9e555a0

Browse files
committed
Merge branch 'master' of github.com:dankamongmen/notcurses
2 parents e878b2f + 6263a6e commit 9e555a0

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/lib/render.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -948,35 +948,37 @@ clean_sprixels(notcurses* nc, ncpile* p, fbuf* f, int scrolls){
948948
// method involves a lot of unnecessary copying.
949949
static void
950950
scroll_lastframe(notcurses* nc, unsigned rows){
951+
if(rows == 0){
952+
return;
953+
}
951954
// the top |rows| rows need be released (though not more than the actual
952955
// number of rows!)
953956
if(rows > nc->lfdimy){
954957
rows = nc->lfdimy;
955958
}
959+
// first, release the contents of rows being scrolled out
956960
for(unsigned targy = 0 ; targy < rows ; ++targy){
957961
for(unsigned targx = 0 ; targx < nc->lfdimx ; ++targx){
958962
const size_t damageidx = targy * nc->lfdimx + targx;
959963
nccell* c = &nc->lastframe[damageidx];
960964
pool_release(&nc->pool, c);
961965
}
962966
}
963-
// now for all rows subsequent, up through lfdimy - rows, move them back.
964-
// if we scrolled all rows, we will not move anything (and we just
965-
// released everything).
967+
// we have zero or more rows to copy up, targeting the first rows. we're
968+
// moving all but the rows we just eliminated. if we scrolled all rows, we
969+
// will not move anything (and we just released everything).
966970
for(unsigned targy = 0 ; targy < nc->lfdimy - rows ; ++targy){
967971
const size_t dstidx = targy * nc->lfdimx;
968972
nccell* dst = &nc->lastframe[dstidx];
969973
const size_t srcidx = dstidx + rows * nc->lfdimx;
970974
const nccell* src = &nc->lastframe[srcidx];
971975
memcpy(dst, src, sizeof(*dst) * nc->lfdimx);
972976
}
973-
// now for the last |rows| rows, initialize them to 0.
974-
unsigned targy = nc->lfdimy - rows;
975-
while(targy < nc->lfdimy){
977+
// now initialize the last |rows| rows to 0
978+
for(unsigned targy = nc->lfdimy - rows ; targy < nc->lfdimy ; ++targy){
976979
const size_t dstidx = targy * nc->lfdimx;
977980
nccell* dst = &nc->lastframe[dstidx];
978981
memset(dst, 0, sizeof(*dst) * nc->lfdimx);
979-
++targy;
980982
}
981983
}
982984

0 commit comments

Comments
 (0)