Message ID | 86b06f3ee95225030fb0e2461a4136d8025c6167.camel@lsferreira.net |
---|---|
State | New |
Headers |
Return-Path: <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> 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 <patchwork@sourceware.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <gcc-patches@gcc.gnu.org>; 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 <contact@lsferreira.net> To: gcc-patches@gcc.gnu.org Date: Wed, 29 Sep 2021 16:32:45 +0100 Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-zcc0SX/eOWtTIUsD6j58" 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 <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" <gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org> |
Series |
libiberty: d-demangle: use appendc for single chars append
|
|
Commit Message
Luís Ferreira
Sept. 29, 2021, 3:32 p.m. UTC
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 <contact@lsferreira.net>
---
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;
}
Comments
On 9/29/2021 9:32 AM, Luís Ferreira wrote: > This may be optimized by some modern smart compilers inliner, but since > strlen can be an external source, this can produce unoptimized code. strlen has very well defined semantics by ISO and even if it's defined externally compilers know those semantics and can optimize appropriately. In fact, if you build a testcase, compile it with a modern compiler, you should see the call to strlen optimized away & the call to memcpy turned into a simple store. So I just don't see the value in adding more code here when we can just let the optimizer do its job and get the same result. I won't object if Iain wants to go forward with this patch, but I'm not going forward with it independently. jeff
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)