From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 124052 invoked by alias); 9 Jun 2019 15:17:14 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Received: (qmail 124042 invoked by uid 89); 9 Jun 2019 15:17:14 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-25.4 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE,RCVD_IN_SORBS_WEB,SPF_PASS autolearn=ham version=3.3.1 spammy=H*MI:icu, H*Ad:D*icu, ca, proceed X-HELO: mail-ua1-f65.google.com Received: from mail-ua1-f65.google.com (HELO mail-ua1-f65.google.com) (209.85.222.65) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Sun, 09 Jun 2019 15:17:12 +0000 Received: by mail-ua1-f65.google.com with SMTP id s4so2203985uad.7 for ; Sun, 09 Jun 2019 08:17:12 -0700 (PDT) Return-Path: Received: from shawn-ThinkPad-L420.hitronhub.home ([190.233.49.202]) by smtp.gmail.com with ESMTPSA id 23sm1332029vkx.55.2019.06.09.08.17.09 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Sun, 09 Jun 2019 08:17:10 -0700 (PDT) From: Shawn Landden To: gdb-patches@sourceware.org Cc: Shawn Landden Subject: [PATCH] Fix slow and non-deterministic behavior of isspace() and tolower() Date: Sun, 09 Jun 2019 15:17:00 -0000 Message-Id: <20190609151704.16061-1-shawn@git.icu> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SW-Source: 2019-06/txt/msg00187.txt.bz2 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