This is the mail archive of the mailing list for the GDB project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Fix slow and non-deterministic behavior of isspace() and tolower()

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;
 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;

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]