@@ -948,35 +948,37 @@ clean_sprixels(notcurses* nc, ncpile* p, fbuf* f, int scrolls){
948
948
// method involves a lot of unnecessary copying.
949
949
static void
950
950
scroll_lastframe (notcurses * nc , unsigned rows ){
951
+ if (rows == 0 ){
952
+ return ;
953
+ }
951
954
// the top |rows| rows need be released (though not more than the actual
952
955
// number of rows!)
953
956
if (rows > nc -> lfdimy ){
954
957
rows = nc -> lfdimy ;
955
958
}
959
+ // first, release the contents of rows being scrolled out
956
960
for (unsigned targy = 0 ; targy < rows ; ++ targy ){
957
961
for (unsigned targx = 0 ; targx < nc -> lfdimx ; ++ targx ){
958
962
const size_t damageidx = targy * nc -> lfdimx + targx ;
959
963
nccell * c = & nc -> lastframe [damageidx ];
960
964
pool_release (& nc -> pool , c );
961
965
}
962
966
}
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).
966
970
for (unsigned targy = 0 ; targy < nc -> lfdimy - rows ; ++ targy ){
967
971
const size_t dstidx = targy * nc -> lfdimx ;
968
972
nccell * dst = & nc -> lastframe [dstidx ];
969
973
const size_t srcidx = dstidx + rows * nc -> lfdimx ;
970
974
const nccell * src = & nc -> lastframe [srcidx ];
971
975
memcpy (dst , src , sizeof (* dst ) * nc -> lfdimx );
972
976
}
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 ){
976
979
const size_t dstidx = targy * nc -> lfdimx ;
977
980
nccell * dst = & nc -> lastframe [dstidx ];
978
981
memset (dst , 0 , sizeof (* dst ) * nc -> lfdimx );
979
- ++ targy ;
980
982
}
981
983
}
982
984
0 commit comments