From patchwork Wed Sep 29 15:32:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Lu=C3=ADs_Ferreira?= X-Patchwork-Id: 45559 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 552B03857C4E for ; Wed, 29 Sep 2021 15:33:06 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from 15.mo6.mail-out.ovh.net (15.mo6.mail-out.ovh.net [188.165.39.161]) by sourceware.org (Postfix) with ESMTPS id ADEC43858406 for ; Wed, 29 Sep 2021 15:32:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org ADEC43858406 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=lsferreira.net Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=lsferreira.net Received: from player762.ha.ovh.net (unknown [10.110.208.115]) by mo6.mail-out.ovh.net (Postfix) with ESMTP id 6743126392A for ; Wed, 29 Sep 2021 17:32:47 +0200 (CEST) Received: from lsferreira.net (252.131.62.94.rev.vodafone.pt [94.62.131.252]) (Authenticated sender: contact@lsferreira.net) by player762.ha.ovh.net (Postfix) with ESMTPSA id 87B5122A3F99D for ; Wed, 29 Sep 2021 15:32:46 +0000 (UTC) Authentication-Results: garm.ovh; auth=pass (GARM-100R00338cade7b-765b-44fa-aa00-dbfd834a7d0b, 2FC05558ACBD31F08628CC07958FA02A3D172E3F) smtp.auth=contact@lsferreira.net X-OVh-ClientIp: 94.62.131.252 Message-ID: <86b06f3ee95225030fb0e2461a4136d8025c6167.camel@lsferreira.net> Subject: [PATCH] libiberty: d-demangle: use appendc for single chars append From: =?iso-8859-1?q?Lu=EDs?= Ferreira To: gcc-patches@gcc.gnu.org Date: Wed, 29 Sep 2021 16:32:45 +0100 User-Agent: Evolution 3.40.4 MIME-Version: 1.0 X-Ovh-Tracer-Id: 9736219446508189719 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvtddrudekvddgkeekucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefkuffhvffftggfggesghdtreertderjeenucfhrhhomhepnfhuvohsucfhvghrrhgvihhrrgcuoegtohhnthgrtghtsehlshhfvghrrhgvihhrrgdrnhgvtheqnecuggftrfgrthhtvghrnhepgfeifffffffhfffhgeffteejueeuveelfeffhfeggeejvddtveeltdekgefggfelnecukfhppedtrddtrddtrddtpdelgedriedvrddufedurddvhedvnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmohguvgepshhmthhpqdhouhhtpdhhvghlohepphhlrgihvghrjeeivddrhhgrrdhovhhhrdhnvghtpdhinhgvtheptddrtddrtddrtddpmhgrihhlfhhrohhmpegtohhnthgrtghtsehlshhfvghrrhgvihhrrgdrnhgvthdprhgtphhtthhopehgtggtqdhprghttghhvghssehgtggtrdhgnhhurdhorhhg X-Spam-Status: No, score=-11.4 required=5.0 tests=BAYES_00, GIT_PATCH_0, KAM_DMARC_STATUS, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" This may be optimized by some modern smart compilers inliner, but since strlen can be an external source, this can produce unoptimized code. Signed-off-by: Luís Ferreira --- libiberty/d-demangle.c | 60 ++++++++++++++++++++++++------------------ 1 file changed, 34 insertions(+), 26 deletions(-) { @@ -664,7 +672,7 @@ dlang_function_type (string *decl, const char *mangled, struct dlang_info *info) /* Append to decl in order. */ string_appendn (decl, type.b, string_length (&type)); string_appendn (decl, args.b, string_length (&args)); - string_append (decl, " "); + string_appendc (decl, ' '); string_appendn (decl, attr.b, string_length (&attr)); string_delete (&attr); @@ -816,9 +824,9 @@ dlang_type (string *decl, const char *mangled, struct dlang_info *info) mangled++; } mangled = dlang_type (decl, mangled, info); - string_append (decl, "["); + string_appendc (decl, '['); string_appendn (decl, numptr, num); - string_append (decl, "]"); + string_appendc (decl, ']'); return mangled; } case 'H': /* associative array (T[T]) */ @@ -832,9 +840,9 @@ dlang_type (string *decl, const char *mangled, struct dlang_info *info) sztype = string_length (&type); mangled = dlang_type (decl, mangled, info); - string_append (decl, "["); + string_appendc (decl, '['); string_appendn (decl, type.b, sztype); - string_append (decl, "]"); + string_appendc (decl, ']'); string_delete (&type); return mangled; @@ -844,7 +852,7 @@ dlang_type (string *decl, const char *mangled, struct dlang_info *info) if (!dlang_call_convention_p (mangled)) { mangled = dlang_type (decl, mangled, info); - string_append (decl, "*"); + string_appendc (decl, '*'); return mangled; } /* Fall through */ @@ -1181,7 +1189,7 @@ dlang_parse_integer (string *decl, const char *mangled, char type) { /* Represent as a character literal. */ char c = (char) val; - string_appendn (decl, &c, 1); + string_appendc (decl, c); } else { @@ -1297,7 +1305,7 @@ dlang_parse_real (string *decl, const char *mangled) /* Hexadecimal prefix and leading bit. */ if (*mangled == 'N') { - string_append (decl, "-"); + string_appendc (decl, '-'); mangled++; } @@ -1305,14 +1313,14 @@ dlang_parse_real (string *decl, const char *mangled) return NULL; string_append (decl, "0x"); - string_appendn (decl, mangled, 1); - string_append (decl, "."); + string_appendc (decl, *mangled); + string_appendc (decl, '.'); mangled++; /* Significand. */ while (ISXDIGIT (*mangled)) { - string_appendn (decl, mangled, 1); + string_appendc (decl, *mangled); mangled++; } @@ -1325,7 +1333,7 @@ dlang_parse_real (string *decl, const char *mangled) if (*mangled == 'N') { - string_append (decl, "-"); + string_appendc (decl, '-'); mangled++; } @@ -1352,7 +1360,7 @@ dlang_parse_string (string *decl, const char *mangled) return NULL; mangled++; - string_append (decl, "\""); + string_appendc (decl, '\"'); while (len--) { char val; @@ -1365,7 +1373,7 @@ dlang_parse_string (string *decl, const char *mangled) switch (val) { case ' ': - string_append (decl, " "); + string_appendc (decl, ' '); break; case '\t': string_append (decl, "\\t"); @@ -1415,7 +1423,7 @@ dlang_parse_arrayliteral (string *decl, const char *mangled, if (mangled == NULL) return NULL; - string_append (decl, "["); + string_appendc (decl, '['); while (elements--) { mangled = dlang_value (decl, mangled, NULL, '\0', info); @@ -1426,7 +1434,7 @@ dlang_parse_arrayliteral (string *decl, const char *mangled, string_append (decl, ", "); } - string_append (decl, "]"); + string_appendc (decl, ']'); return mangled; } @@ -1442,14 +1450,14 @@ dlang_parse_assocarray (string *decl, const char *mangled, if (mangled == NULL) return NULL; - string_append (decl, "["); + string_appendc (decl, '['); while (elements--) { mangled = dlang_value (decl, mangled, NULL, '\0', info); if (mangled == NULL) return NULL; - string_append (decl, ":"); + string_appendc (decl, ':'); mangled = dlang_value (decl, mangled, NULL, '\0', info); if (mangled == NULL) return NULL; @@ -1458,7 +1466,7 @@ dlang_parse_assocarray (string *decl, const char *mangled, string_append (decl, ", "); } - string_append (decl, "]"); + string_appendc (decl, ']'); return mangled; } @@ -1477,7 +1485,7 @@ dlang_parse_structlit (string *decl, const char *mangled, const char *name, if (name != NULL) string_append (decl, name); - string_append (decl, "("); + string_appendc (decl, '('); while (args--) { mangled = dlang_value (decl, mangled, NULL, '\0', info); @@ -1488,7 +1496,7 @@ dlang_parse_structlit (string *decl, const char *mangled, const char *name, string_append (decl, ", "); } - string_append (decl, ")"); + string_appendc (decl, ')'); return mangled; } @@ -1512,7 +1520,7 @@ dlang_value (string *decl, const char *mangled, const char *name, char type, /* Integral values. */ case 'N': mangled++; - string_append (decl, "-"); + string_appendc (decl, '-'); mangled = dlang_parse_integer (decl, mangled, type); break; @@ -1538,12 +1546,12 @@ dlang_value (string *decl, const char *mangled, const char *name, char type, case 'c': mangled++; mangled = dlang_parse_real (decl, mangled); - string_append (decl, "+"); + string_appendc (decl, '+'); if (mangled == NULL || *mangled != 'c') return NULL; mangled++; mangled = dlang_parse_real (decl, mangled); - string_append (decl, "i"); + string_appendc (decl, 'i'); break; /* String values. */ @@ -1651,7 +1659,7 @@ dlang_parse_qualified (string *decl, const char *mangled, do { if (n++) - string_append (decl, "."); + string_appendc (decl, '.'); /* Skip over anonymous symbols. */ while (*mangled == '0') @@ -1723,7 +1731,7 @@ dlang_parse_tuple (string *decl, const char *mangled, struct dlang_info *info) string_append (decl, ", "); } - string_append (decl, ")"); + string_appendc (decl, ')'); return mangled; } diff --git a/libiberty/d-demangle.c b/libiberty/d-demangle.c index 3adf7b562d1..9b12c8158bb 100644 --- a/libiberty/d-demangle.c +++ b/libiberty/d-demangle.c @@ -144,6 +144,14 @@ string_appendn (string *p, const char *s, size_t n) } } +static void +string_appendc (string *p, char c) +{ + string_need (p, 1); + *p->p = c; + p->p++; +} + static void string_prependn (string *p, const char *s, size_t n)