Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
* [PATCH] Fix slow and non-deterministic behavior of isspace() and tolower()
@ 2019-06-09 15:17 Shawn Landden
  2019-06-09 15:42 ` Eli Zaretskii
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Shawn Landden @ 2019-06-09 15:17 UTC (permalink / raw)
  To: gdb-patches; +Cc: Shawn Landden

I was getting 8% and 6% cpu usage in tolower() and isspace(),
respectively, waiting for a breakpoint on ppc64el.

Also, gdb doesn't want non-deterministic behavior here.
---
 gdb/utils.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gdb/utils.c b/gdb/utils.c
index 9686927473..d36b942cc5 100644
--- a/gdb/utils.c
+++ b/gdb/utils.c
@@ -2626,10 +2626,29 @@ strcmp_iw (const char *string1, const char *string2)
    user searches for "foo", then strcmp will sort "foo" before "foo$".
    Then lookup_partial_symbol will notice that strcmp_iw("foo$",
    "foo") is false, so it won't proceed to the actual match of
    "foo(int)" with "foo".  */
 
+/* glibc versions of these have non-deterministic locale-dependant behavior,
+   and are very slow, taking 8% and 6% of total CPU time with some use-cases */
+#undef isspace
+static int isspace(int c)
+{
+  return c == ' ' || (unsigned)c-'\t' < 5;
+}
+#undef isupper
+static int isupper(int c)
+{
+  return (unsigned)c-'A' < 26;
+}
+#undef tolower
+static int tolower(int c)
+{
+  if (isupper(c)) return c | 32;
+  return c;
+}
+
 int
 strcmp_iw_ordered (const char *string1, const char *string2)
 {
   const char *saved_string1 = string1, *saved_string2 = string2;
   enum case_sensitivity case_pass = case_sensitive_off;
-- 
2.20.1


^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2019-06-21 21:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-06-09 15:17 [PATCH] Fix slow and non-deterministic behavior of isspace() and tolower() Shawn Landden
2019-06-09 15:42 ` Eli Zaretskii
2019-06-09 15:51   ` Shawn Landden
2019-06-10 21:14 ` John Baldwin
2019-06-10 21:30 ` [PATCH v2] " Shawn Landden
2019-06-21 17:35   ` Pedro Alves
2019-06-21 17:59     ` Shawn Landden
2019-06-21 18:08       ` Pedro Alves
2019-06-21 19:20   ` [PATCH] " Shawn Landden
2019-06-21 20:12     ` Pedro Alves
2019-06-21 20:30       ` Shawn Landden
2019-06-21 21:14         ` Pedro Alves

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox