[PATCH] Reduce memory required by build_string
Richard Guenther
rguenther@suse.de
Mon Jun 26 13:52:00 GMT 2006
On Mon, 26 Jun 2006, Richard Guenther wrote:
> On Mon, 26 Jun 2006, Jakub Jelinek wrote:
>
> > > !
> > > ! /* 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.
Bootstrapped and tested on x86_64-unknown-linux-gnu.
Ok for mainline?
Thanks,
Richard.
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,1128 ----
{
tree s;
size_t length;
!
! /* Do not waste bytes provided by padding of struct tree_string. */
! length = len + offsetof (struct tree_string, str) + 1;
#ifdef GATHER_STATISTICS
tree_node_counts[(int) c_kind]++;
More information about the Gcc-patches
mailing list