vim-patch:9.1.0218: Unnecessary multiplications in backspace code (#28075)

Problem:  Unnecessary multiplications in backspace code, as
          "col / ts * ts" is the same as "col - col % ts".
Solution: Change "col / ts * ts" to "col - col % ts".  Adjust the loop
          and the comments ins_bs() to be easier to understand.  Update
          tests to reset 'smarttab' properly.
          (zeertzjq)

closes: vim/vim#14308

8ede7a0694
This commit is contained in:
zeertzjq
2024-03-28 18:20:38 +08:00
committed by GitHub
parent 6364fc617d
commit 08b8ccd733
3 changed files with 39 additions and 17 deletions

View File

@@ -177,7 +177,7 @@ colnr_T tabstop_start(colnr_T col, int ts, colnr_T *vts)
colnr_T tabcol = 0;
if (vts == NULL || vts[0] == 0) {
return ((col / ts) * ts);
return col - col % ts;
}
const int tabcount = vts[0];
@@ -189,7 +189,7 @@ colnr_T tabstop_start(colnr_T col, int ts, colnr_T *vts)
}
const int excess = (tabcol % vts[tabcount]);
return (excess + ((col - excess) / vts[tabcount]) * vts[tabcount]);
return col - (col - excess) % vts[tabcount];
}
/// Find the number of tabs and spaces necessary to get from one column