Re: [PATCH 1/2] Change vec<,,vl_embed>::m_vecdata refrences into address ()

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 02:46:21PM +0100, Richard Biener wrote:
> As preparation to remove m_vecdata in the vl_embed vector this
> changes references to it into calls to address ().
> 
> As I was here it also fixes ::contains to avoid repeated bounds
> checking and the same issue in ::lower_bound which also suffers
> from unnecessary copying around values.
> 
>   * vec.h: Change m_vecdata references to address ().
>   * vec.h (vec::lower_bound): Adjust to
>   take a const reference to the object, use address to
>   access data.
>   (vec::contains): Use address to access data.
>   (vec::operator[]): Use address instead of
>   m_vecdata to access data.
>   (vec::iterate): Likewise.
>   (vec::copy): Likewise.
>   (vec::quick_push): Likewise.
>   (vec::pop): Likewise.
>   (vec::quick_insert): Likewise.
>   (vec::ordered_remove): Likewise.
>   (vec::unordered_remove): Likewise.
>   (vec::block_remove): Likewise.
>   (vec::address): Likewise.

Ok, thanks.

Jakub



Re: [PATCH 1/2] Change vec<, , vl_embed>::m_vecdata refrences into address ()

2023-02-24 Thread Richard Biener via Gcc-patches
On Fri, 24 Feb 2023, Jakub Jelinek wrote:

> On Fri, Feb 24, 2023 at 12:32:45PM +0100, Richard Biener via Gcc-patches 
> wrote:
> > --- a/gcc/vec.h
> > +++ b/gcc/vec.h
> > @@ -614,7 +614,7 @@ public:
> >T *bsearch (const void *key, int (*compar)(const void *, const void *));
> >T *bsearch (const void *key,
> >   int (*compar)(const void *, const void *, void *), void *);
> > -  unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
> > +  unsigned lower_bound (const T &, bool (*)(const T &, const T &)) const;
> 
> Missing space after (*) while you're there.
> 
> > @@ -929,7 +929,7 @@ vec::iterate (unsigned ix, T *ptr) const
> >  {
> >if (ix < m_vecpfx.m_num)
> >  {
> > -  *ptr = m_vecdata[ix];
> > +  *ptr = address()[ix];
> 
> Missing space before ().
> 
> > @@ -1118,7 +1118,7 @@ inline void
> >  vec::unordered_remove (unsigned ix)
> >  {
> >gcc_checking_assert (ix < length ());
> > -  m_vecdata[ix] = m_vecdata[--m_vecpfx.m_num];
> > +  address ()[ix] = address ()[--m_vecpfx.m_num];
> >  }
> 
> As address () is used twice here, can't we stick it into a temporary
> and use twice then?
> 
> > @@ -1249,8 +1249,11 @@ vec::contains (const T &search) const
> >  {
> >unsigned int len = length ();
> >for (unsigned int i = 0; i < len; i++)
> > -if ((*this)[i] == search)
> > -  return true;
> > +{
> > +  const T *slot = &address ()[i];
> > +  if (*slot == search)
> > +   return true;
> 
> Similarly, can't we do address () once before the loop into a temporary?
> 
> >  template
> >  unsigned
> > -vec::lower_bound (T obj, bool (*lessthan)(const T &, const 
> > T &))
> > +vec::lower_bound (const T &obj,
> > + bool (*lessthan)(const T &, const T &))
> 
> ) ( while you're at it.
> 
> Otherwise LGTM.

All fixed.

Richard.


Re: [PATCH 1/2] Change vec<, , vl_embed>::m_vecdata refrences into address ()

2023-02-24 Thread Jakub Jelinek via Gcc-patches
On Fri, Feb 24, 2023 at 12:32:45PM +0100, Richard Biener via Gcc-patches wrote:
> --- a/gcc/vec.h
> +++ b/gcc/vec.h
> @@ -614,7 +614,7 @@ public:
>T *bsearch (const void *key, int (*compar)(const void *, const void *));
>T *bsearch (const void *key,
> int (*compar)(const void *, const void *, void *), void *);
> -  unsigned lower_bound (T, bool (*)(const T &, const T &)) const;
> +  unsigned lower_bound (const T &, bool (*)(const T &, const T &)) const;

Missing space after (*) while you're there.

> @@ -929,7 +929,7 @@ vec::iterate (unsigned ix, T *ptr) const
>  {
>if (ix < m_vecpfx.m_num)
>  {
> -  *ptr = m_vecdata[ix];
> +  *ptr = address()[ix];

Missing space before ().

> @@ -1118,7 +1118,7 @@ inline void
>  vec::unordered_remove (unsigned ix)
>  {
>gcc_checking_assert (ix < length ());
> -  m_vecdata[ix] = m_vecdata[--m_vecpfx.m_num];
> +  address ()[ix] = address ()[--m_vecpfx.m_num];
>  }

As address () is used twice here, can't we stick it into a temporary
and use twice then?

> @@ -1249,8 +1249,11 @@ vec::contains (const T &search) const
>  {
>unsigned int len = length ();
>for (unsigned int i = 0; i < len; i++)
> -if ((*this)[i] == search)
> -  return true;
> +{
> +  const T *slot = &address ()[i];
> +  if (*slot == search)
> + return true;

Similarly, can't we do address () once before the loop into a temporary?

>  template
>  unsigned
> -vec::lower_bound (T obj, bool (*lessthan)(const T &, const T 
> &))
> +vec::lower_bound (const T &obj,
> +   bool (*lessthan)(const T &, const T &))

) ( while you're at it.

Otherwise LGTM.

Jakub