From: Ian Lance Taylor <iant@google.com>
To: Riccardo Lucchese <riccardo.lucchese@gmail.com>
Cc: gcc-help@gcc.gnu.org
Subject: Re: optimisation question
Date: Thu, 17 May 2007 18:40:00 -0000 [thread overview]
Message-ID: <m3bqgjl2fm.fsf@localhost.localdomain> (raw)
In-Reply-To: <1179420679.19673.9.camel@desktop>
Riccardo Lucchese <riccardo.lucchese@gmail.com> writes:
> I'm working on GTK code; let's say we have some code like:
>
> widget->privData->color = ...;
> widget->privData->l = ...;
> widget->privData->w = ...;
> widget->privData->foo = ...;
>
> does gcc already optimise widget->privData saving its value one time and
> than using it? or generated binary just does what is written(literally -
> "reference per reference")?
It depends on the data types. If it is possible that the assignment
to, e.g., widget->privData->color could change widget->privData itself
(perhaps because widget->privData == widget), then gcc can not
optimize the following load of widget->privData.
> Would it be better to do:
> WidgetPrivData* priv = widget->privData;
> priv->color = ...;
> priv->l = ...;
> priv->w = ...;
> priv->foo = ...;
In some cases, yes.
Ian
prev parent reply other threads:[~2007-05-17 18:40 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-17 16:54 Riccardo Lucchese
2007-05-17 18:40 ` Ian Lance Taylor [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=m3bqgjl2fm.fsf@localhost.localdomain \
--to=iant@google.com \
--cc=gcc-help@gcc.gnu.org \
--cc=riccardo.lucchese@gmail.com \
/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).