mirror of
https://github.com/rkd77/elinks.git
synced 2024-12-04 14:46:47 -05:00
Improve performance with textareas + UTF-8 I/O
If utf8_char2cells isn't told where the string that contains the given UTF-8 character ends, it computes that itself. Two users of utf8_char2cells, format_textutf8 and split_line, were calling utf8_char2cells in a loop without providing the end of the string, resulting in numerous calls by utf8_char2cells to strlen. With this patch, format_textutf8 and split_line each find the end of the string once and provide it to utf8_char2cells. This particularly improves performance with textareas, since format_textutf8 is called multiple times each time the user interacts with the textarea and when it must be redrawn. Closes: Bug 823 - Big textarea is too slow with CONFIG_UTF8
This commit is contained in:
parent
a3c27ee02e
commit
5537a3f977
@ -45,6 +45,7 @@ split_line(unsigned char *text, int max_width, int *cells)
|
|||||||
#endif /* CONFIG_UTF8 */
|
#endif /* CONFIG_UTF8 */
|
||||||
{
|
{
|
||||||
unsigned char *split = text;
|
unsigned char *split = text;
|
||||||
|
unsigned char *text_end = split + strlen(split);
|
||||||
int cells_save = *cells;
|
int cells_save = *cells;
|
||||||
|
|
||||||
if (max_width <= 0) return 0;
|
if (max_width <= 0) return 0;
|
||||||
@ -59,7 +60,7 @@ split_line(unsigned char *text, int max_width, int *cells)
|
|||||||
|
|
||||||
next_split = split;
|
next_split = split;
|
||||||
|
|
||||||
*cells += utf8_char2cells(split, NULL);
|
*cells += utf8_char2cells(split, text_end);
|
||||||
while (*next_split && next_split != next_char_begin)
|
while (*next_split && next_split != next_char_begin)
|
||||||
next_split++;
|
next_split++;
|
||||||
|
|
||||||
@ -70,7 +71,7 @@ split_line(unsigned char *text, int max_width, int *cells)
|
|||||||
next_split++;
|
next_split++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
*cells += utf8_char2cells(next_split, NULL);
|
*cells += utf8_char2cells(next_split, text_end);
|
||||||
next_char_begin += utf8charlen(next_split);
|
next_char_begin += utf8charlen(next_split);
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
@ -67,6 +67,7 @@ format_textutf8(unsigned char *text, int width, enum form_wrap wrap, int format)
|
|||||||
int line_number = 0;
|
int line_number = 0;
|
||||||
int begin = 0;
|
int begin = 0;
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
unsigned char *text_end;
|
||||||
int skip;
|
int skip;
|
||||||
unsigned char *wrappos=NULL;
|
unsigned char *wrappos=NULL;
|
||||||
int chars_cells=0; /* Number of console chars on line */
|
int chars_cells=0; /* Number of console chars on line */
|
||||||
@ -78,8 +79,9 @@ format_textutf8(unsigned char *text, int width, enum form_wrap wrap, int format)
|
|||||||
if (!realloc_line_info(&line, 0))
|
if (!realloc_line_info(&line, 0))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
text_end = text + strlen(text);
|
||||||
while (text[pos]) {
|
while (text[pos]) {
|
||||||
int char_cells = utf8_char2cells(&text[pos], NULL);
|
int char_cells = utf8_char2cells(&text[pos], text_end);
|
||||||
|
|
||||||
if (text[pos] == ' ')
|
if (text[pos] == ' ')
|
||||||
wrappos = &text[pos];
|
wrappos = &text[pos];
|
||||||
|
Loading…
Reference in New Issue
Block a user