Cleanup: reduce variable scope & use const values

This commit is contained in:
Campbell Barton
2024-01-18 15:18:13 +11:00
parent 12195eb6e1
commit 0192a955be
2 changed files with 17 additions and 26 deletions
@@ -254,7 +254,7 @@ void space_text_wrap_offset(
*offc = 0;
for (i = 0, j = 0; linep->line[j]; j += BLI_str_utf8_size_safe(linep->line + j)) {
int chars;
int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */
const int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */
/* Mimic replacement of tabs */
ch = linep->line[j];
@@ -331,7 +331,7 @@ void space_text_wrap_offset_in_line(
cursin = BLI_str_utf8_offset_to_column(linein->line, linein->len, cursin);
for (i = 0, j = 0; linein->line[j]; j += BLI_str_utf8_size_safe(linein->line + j)) {
int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab */
const int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab */
/* Mimic replacement of tabs */
ch = linein->line[j];
@@ -395,10 +395,9 @@ int space_text_get_char_pos(const SpaceText *st, const char *line, int cur)
static const char *txt_utf8_forward_columns(const char *str, int columns, int *padding)
{
int col;
const char *p = str;
while (*p) {
col = BLI_str_utf8_char_width_safe(p);
const int col = BLI_str_utf8_char_width_safe(p);
if (columns - col < 0) {
break;
}
@@ -524,12 +523,12 @@ static void space_text_draw(const SpaceText *st,
{
const bool use_syntax = (tdc->syntax_highlight && format);
FlattenString fs;
int columns, size, n, w = 0, padding, amount = 0;
int n, w = 0, padding, amount = 0;
const char *in = nullptr;
for (n = flatten_string(st, &fs, str), str = fs.buf; n > 0; n--) {
columns = BLI_str_utf8_char_width_safe(str);
size = BLI_str_utf8_size_safe(str);
const int columns = BLI_str_utf8_char_width_safe(str);
const int size = BLI_str_utf8_size_safe(str);
if (!in) {
if (w >= cshift) {
@@ -817,7 +816,7 @@ int space_text_get_visible_lines(const SpaceText *st, const ARegion *region, con
start = 0;
end = max;
for (i = 0, j = 0; str[j]; j += BLI_str_utf8_size_safe(str + j)) {
int columns = BLI_str_utf8_char_width_safe(str + j); /* = 1 for tab */
const int columns = BLI_str_utf8_char_width_safe(str + j); /* = 1 for tab */
/* Mimic replacement of tabs */
ch = str[j];
+10 -18
View File
@@ -1768,7 +1768,7 @@ static int space_text_get_cursor_rel(
for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe(linein->line + j)) {
int chars;
int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab */
const int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab */
/* Mimic replacement of tabs */
ch = linein->line[j];
@@ -1972,7 +1972,7 @@ static void txt_wrap_move_bol(SpaceText *st, ARegion *region, const bool sel)
for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
int chars;
int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab */
const int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab */
/* Mimic replacement of tabs */
ch = (*linep)->line[j];
@@ -2059,7 +2059,7 @@ static void txt_wrap_move_eol(SpaceText *st, ARegion *region, const bool sel)
for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
int chars;
int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab */
const int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab */
/* Mimic replacement of tabs */
ch = (*linep)->line[j];
@@ -3063,12 +3063,9 @@ static int flatten_width(SpaceText *st, const char *str)
int total = 0;
for (int i = 0; str[i]; i += BLI_str_utf8_size_safe(str + i)) {
if (str[i] == '\t') {
total += st->tabnumber - total % st->tabnumber;
}
else {
total += BLI_str_utf8_char_width_safe(str + i);
}
const int columns = (str[i] == '\t') ? (st->tabnumber - total % st->tabnumber) :
BLI_str_utf8_char_width_safe(str + i);
total += columns;
}
return total;
@@ -3076,16 +3073,11 @@ static int flatten_width(SpaceText *st, const char *str)
static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
{
int i = 0, j = 0, col;
int i = 0, j = 0;
while (*(str + j)) {
if (str[j] == '\t') {
col = st->tabnumber - i % st->tabnumber;
}
else {
col = BLI_str_utf8_char_width_safe(str + j);
}
const int col = (str[j] == '\t') ? (st->tabnumber - i % st->tabnumber) :
BLI_str_utf8_char_width_safe(str + j);
if (i + col > index) {
break;
}
@@ -3142,7 +3134,7 @@ static void space_text_cursor_set_to_pos_wrapped(
j += BLI_str_utf8_size_safe(linep->line + j))
{
int chars;
int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */
const int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */
/* Mimic replacement of tabs */
if (ch == '\t') {