top: an efficiency tweak to extra wide character logic
When I recently added extra wide character support for locales like zh_CN, I didn't worry about some overhead associated with the new calls to 'mbtowc' & 'wcwidth'. That's because such overhead was usually incurred with user interactions, not a normal iterative top display. There was, however, one area where this overhead would impact the normal iterative top mode - that's with the Summary display. So I peeked at the glibc source code. As it turns out, the costs of executing those 'mbtowc' and 'wcwidth' functions were not at all insignificant. So, this patch will avoid them in the vast majority of instances, while still enabling extra wide characters. Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
parent
0192197198
commit
7e1dfc12b6
@ -511,11 +511,12 @@ static char UTF8_tab[] = {
|
|||||||
static inline int utf8_cols (const unsigned char *p, int n) {
|
static inline int utf8_cols (const unsigned char *p, int n) {
|
||||||
#ifndef OFF_XTRAWIDE
|
#ifndef OFF_XTRAWIDE
|
||||||
wchar_t wc;
|
wchar_t wc;
|
||||||
int wlen;
|
|
||||||
|
|
||||||
(void)mbtowc(&wc, (const char *)p, n);
|
if (n > 1) {
|
||||||
if ((wlen = wcwidth(wc)) < 1) wlen = 1;
|
(void)mbtowc(&wc, (const char *)p, n);
|
||||||
return wlen;
|
if ((n = wcwidth(wc)) < 1) n = 1;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
#else
|
#else
|
||||||
(void)p; (void)n;
|
(void)p; (void)n;
|
||||||
return 1;
|
return 1;
|
||||||
|
Loading…
Reference in New Issue
Block a user