top: make the 'utf8_proper_col' routine more efficient

This patch better exploits short-circuit evaluation in
two 'if' tests. In every case, the 1st of 2 conditions
in each 'if' test must take place but it always proves
true with each iteration for 1 of the 'if' statements.
Thus, the 2nd condition will have to be evaluated too.

By reordering 2 tests in each 'if', we can ensure that
the 2nd condition will then be tested much less often.

Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2017-10-04 00:00:00 -05:00 committed by Craig Small
parent ca566ad554
commit a74f604441

View File

@ -562,10 +562,10 @@ static int utf8_proper_col (const char *str, int col, int tophysical) {
while (*p) {
// -1 represents a decoding error, don't encourage repositioning ...
if (0 > (clen = UTF8_tab[*p])) return col;
if (tophysical && cnum + 1 > col) break;
if (cnum + 1 > col && tophysical) break;
p += clen;
tlen += clen;
if (!tophysical && tlen > col) break;
if (tlen > col && !tophysical) break;
++cnum;
}
return tophysical ? tlen : cnum;