From: Qing Zhao <qing.zhao@oracle.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: "rguenther@suse.de" <rguenther@suse.de>,
"gcc-patches@gcc.gnu.org" <gcc-patches@gcc.gnu.org>
Subject: Re: [PATCH] Fixing PR107411
Date: Mon, 20 Feb 2023 17:45:21 +0000 [thread overview]
Message-ID: <C5A4D810-5DDD-4547-8785-287208DCB954@oracle.com> (raw)
In-Reply-To: <Y/OPBpgIgJACaSka@tucnak>
> On Feb 20, 2023, at 10:17 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>
> On Mon, Feb 20, 2023 at 03:04:51PM +0000, Qing Zhao via Gcc-patches wrote:
>>
>>
>>> On Feb 17, 2023, at 5:35 PM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>
>>> On Fri, Feb 17, 2023 at 10:26:03PM +0000, Qing Zhao via Gcc-patches wrote:
>>>> + else if (!DECL_NAME (lhs_var))
>>>> + {
>>>> + char *lhs_var_name_str
>>>> + = xasprintf ("D.%u", DECL_UID (lhs_var));
>>>
>>> Why xasprintf?
>>
>> Just emulated the code in “gimple_add_init_for_auto_var” without thinking too much. -:)
>>> D.%u can be sprintfed into a fixed size automatic buffer,
>>> say 3 + (HOST_BITS_PER_INT + 2) / 3 would be a good upper bound for the size
>>> of the buffer. Then you don't need to free it...
>>
>> xasprintf is "like a sprintf but provided a pointer to malloc’d storage (without fail)”. If free the pointer properly, then it should be okay, right?
>> In addition to “no need to free”, what other benefit to use sprintf other than xasprintf?
>
> xasprintf+free being significantly slower, exactly because it needs to
> malloc and free later, where both are fairly expensive functions.
> The glibc asprintf for short strings like the above uses a ~ 200 byte
> static buffer, stores in there, later mallocs the needed amount of memory
> and copies it there (so again, another waste because the string needs to be
> copied around), while for longer it can do perhaps many allocations and
> realloc at the end to the right size.
> The libiberty function actually performs the printing twice, once without
> writing result anywhere to compute size, then malloc, then again into the
> malloced buffer.
Okay, thanks a lot for the info.
I will replace xasprintf with sprintf for this patch.
Qing
>
> Jakub
>
prev parent reply other threads:[~2023-02-20 17:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-17 22:26 Qing Zhao
2023-02-17 22:35 ` Jakub Jelinek
2023-02-20 15:04 ` Qing Zhao
2023-02-20 15:17 ` Jakub Jelinek
2023-02-20 17:45 ` Qing Zhao [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=C5A4D810-5DDD-4547-8785-287208DCB954@oracle.com \
--to=qing.zhao@oracle.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=jakub@redhat.com \
--cc=rguenther@suse.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).