comparison src/indent.c @ 34674:bfd2c0032686 v9.1.0218

patch 9.1.0218: Unnecessary multiplications in backspace code Commit: https://github.com/vim/vim/commit/8ede7a069419e0e01368c65a2d0c79d6332aa6cd Author: zeertzjq <zeertzjq@outlook.com> Date: Thu Mar 28 10:30:08 2024 +0100 patch 9.1.0218: Unnecessary multiplications in backspace code 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: #14308 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Thu, 28 Mar 2024 10:45:04 +0100
parents 9e093c96dff6
children
comparison
equal deleted inserted replaced
34673:62e99aaa4fcf 34674:bfd2c0032686
161 colnr_T tabcol = 0; 161 colnr_T tabcol = 0;
162 int t; 162 int t;
163 int excess; 163 int excess;
164 164
165 if (vts == NULL || vts[0] == 0) 165 if (vts == NULL || vts[0] == 0)
166 return (col / ts) * ts; 166 return col - col % ts;
167 167
168 tabcount = vts[0]; 168 tabcount = vts[0];
169 for (t = 1; t <= tabcount; ++t) 169 for (t = 1; t <= tabcount; ++t)
170 { 170 {
171 tabcol += vts[t]; 171 tabcol += vts[t];
172 if (tabcol > col) 172 if (tabcol > col)
173 return tabcol - vts[t]; 173 return tabcol - vts[t];
174 } 174 }
175 175
176 excess = tabcol % vts[tabcount]; 176 excess = tabcol % vts[tabcount];
177 return excess + ((col - excess) / vts[tabcount]) * vts[tabcount]; 177 return col - (col - excess) % vts[tabcount];
178 } 178 }
179 179
180 /* 180 /*
181 * Find the number of tabs and spaces necessary to get from one column 181 * Find the number of tabs and spaces necessary to get from one column
182 * to another. 182 * to another.