[PATCH] Reduce memory required by build_string

Richard Guenther rguenther@suse.de
Mon Jun 26 13:39:00 GMT 2006


On Mon, 26 Jun 2006, Jakub Jelinek wrote:

> On Mon, Jun 26, 2006 at 01:58:30PM +0200, Richard Guenther wrote:
> > 2006-06-26  Richard Guenther  <rguenther@suse.de>
> > 
> > 	* tree.c (build_string): Do not waste tail padding in
> > 	struct tree_string.
> > 
> > Index: tree.c
> > ===================================================================
> > *** tree.c	(revision 115006)
> > --- tree.c	(working copy)
> > *************** build_string (int len, const char *str)
> > *** 1120,1127 ****
> >   {
> >     tree s;
> >     size_t length;
> > !   
> > !   length = len + sizeof (struct tree_string);
> >   
> >   #ifdef GATHER_STATISTICS
> >     tree_node_counts[(int) c_kind]++;
> > --- 1120,1130 ----
> >   {
> >     tree s;
> >     size_t length;
> > ! 
> > !   /* Do not waste bytes provided by padding of struct tree_string.  */
> > !   length = ((len + sizeof (struct tree_string))
> > ! 	    & ~(sizeof (struct tree_string)
> > ! 		- offsetof (struct tree_string, str) - 1));
> 
> How do you know that sizeof (struct tree_string) - offsetof (struct tree_string, str)
> is a power of two?

Only by looking at the struct definition, so yes, you are right.

> I think
>   length = len + offsetof (struct tree_string, str);
> would be much better.

No, but

 length = len + offsetof (struct tree_string, str) + 1;

would work, indeed.  Re-running bootstrap & regtest with this.

Richard.

--
Richard Guenther <rguenther@suse.de>
Novell / SUSE Labs



More information about the Gcc-patches mailing list