]> granicus.if.org Git - procps-ng/commitdiff
library: revert one ancient 'escape_str_utf8' deletion
authorJim Warner <james.warner@comcast.net>
Sun, 21 Aug 2016 05:00:00 +0000 (00:00 -0500)
committerCraig Small <csmall@enc.com.au>
Tue, 23 Aug 2016 11:11:09 +0000 (21:11 +1000)
Profiling revealed a large amount of time spent in the
'escape_str_utf8' function (escape.c) with both of our
NLS branches (newlib and master). That same result was
not seen under an ancient top-3.2.8 program & library.

Well, the 3.2.8 result was ultimately explained by the
absence of a 'setlocale', necessary under NLS support.
Thus, when that ancient library tested for locale, all
it got was 'ANSI_...' & assumed 'UTF-8' wasn't active.

But after a hack to that ancient code to place it on a
par with newlib/master, I still found cost differences
that led me to revisit an old change referenced below.

It turns out that 'iswprint' costs far more than would
a call of 'isprint', even with the extra support code.
So this commit just reverts that five year old change.

Reference(s):
commit 7b0fc19e9d28380dc9790615b93bc3653d6d686e

Signed-off-by: Jim Warner <james.warner@comcast.net>
proc/escape.c

index 2244f54a484cdcc56768eb86b3e7c7139991c410..18b46fde594f42a46eb8f4152ca32406622c8fcc 100644 (file)
@@ -60,6 +60,13 @@ static int escape_str_utf8(char *restrict dst, const char *restrict src, int buf
       my_cells++;
       my_bytes++;
 
+    } else if (len==1) {
+      /* non-multibyte */
+      *(dst++) = isprint(*src) ? *src : '?';
+      src++;
+      my_cells++;
+      my_bytes++;
+
     } else if (!iswprint(wc)) {
       /* multibyte - no printable */
       *(dst++) = '?';