public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* optimisation question
@ 2007-05-17 16:54 Riccardo Lucchese
  2007-05-17 18:40 ` Ian Lance Taylor
  0 siblings, 1 reply; 2+ messages in thread
From: Riccardo Lucchese @ 2007-05-17 16:54 UTC (permalink / raw)
  To: gcc-help

Hi!

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")?

Would it be better to do:
WidgetPrivData* priv = widget->privData;
priv->color = ...;
priv->l = ...;
priv->w = ...;
priv->foo = ...;
 ?

Thank you very much,
Riccardo
riccardo.lucchese@gmail.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: optimisation question
  2007-05-17 16:54 optimisation question Riccardo Lucchese
@ 2007-05-17 18:40 ` Ian Lance Taylor
  0 siblings, 0 replies; 2+ messages in thread
From: Ian Lance Taylor @ 2007-05-17 18:40 UTC (permalink / raw)
  To: Riccardo Lucchese; +Cc: gcc-help

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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2007-05-17 18:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-05-17 16:54 optimisation question Riccardo Lucchese
2007-05-17 18:40 ` Ian Lance Taylor

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).