Mirror of the gdb-patches mailing list
 help / color / mirror / Atom feed
From: Simon Marchi <simark@simark.ca>
To: Tom Tromey <tom@tromey.com>, Simon Marchi <simon.marchi@efficios.com>
Cc: Simon Marchi via Gdb-patches <gdb-patches@sourceware.org>
Subject: Re: [PATCH 2/4] gdbsupport: add array_view copy function
Date: Thu, 18 Nov 2021 15:07:35 -0500	[thread overview]
Message-ID: <e2a8fe92-eed9-4549-1b73-ec8211cc2869@simark.ca> (raw)
In-Reply-To: <87tugbzl7y.fsf@tromey.com>

On 2021-11-16 7:20 p.m., Tom Tromey wrote:
>>> In C++20 I think we could use std::copy by having the array view
>>> iterators implement the contiguous_iterator concept.  So, maybe a
>>> comment to this effect would be good.
>
> Simon> Do you mean we could use std::copy to implement this copy function,
> Simon> instead of using memcpy, and that would deal with the details of copying
> Simon> in the most efficient manner?
>
> Yeah, but IIUC it will only use memcpy or whatever if it sees the
> contiguous_iterator concept (and if the content type is trivially
> copyable).  I'm not sure if there's a way to get this behavior before
> C++20 though.
>
> Tom
>

I did some tests (with g++ 11, if that matters), compiled GDB with
-std=c++11, and it seems like std::copy does the right thing.  When
copying a trivial type (array_view<int>), it ends up using
this __builtin_memmove:

    https://gitlab.com/gnutools/gcc/-/blob/6f4ac4f81f89caac7e74127ed2e6db6bbb3d7426/libstdc++-v3/include/bits/stl_algobase.h#L414-434

When copying a type that has a user-defined copy assignment operator, it
ends up using this manual loop:

    https://gitlab.com/gnutools/gcc/-/blob/6f4ac4f81f89caac7e74127ed2e6db6bbb3d7426/libstdc++-v3/include/bits/stl_algobase.h#L394-412

That seems to be exactly what we want.

Also, reading about std::copy made me realize that we would have to make
sure we handle overlapping ranges correctly.  Using std::copy or
std::copy_backwards (depending on whether the destination comes before
the source) handles that.

I will post an updated series.

Simon

  reply	other threads:[~2021-11-18 20:07 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-08 21:06 [PATCH 1/4] gdb: fix length of array view returned by some value_contents functions Simon Marchi via Gdb-patches
2021-11-08 21:06 ` [PATCH 2/4] gdbsupport: add array_view copy function Simon Marchi via Gdb-patches
2021-11-08 21:11   ` Simon Marchi via Gdb-patches
2021-11-16 20:54     ` Tom Tromey
2021-11-16 20:53   ` Tom Tromey
2021-11-16 21:56     ` Simon Marchi via Gdb-patches
2021-11-17  0:20       ` Tom Tromey
2021-11-18 20:07         ` Simon Marchi [this message]
2021-11-08 21:06 ` [PATCH 3/4] gdb: make extract_integer take an array_view Simon Marchi via Gdb-patches
2021-11-08 21:06 ` [PATCH 4/4] gdb: trivial changes to use array_view Simon Marchi via Gdb-patches
2021-11-16 20:41 ` [PATCH 1/4] gdb: fix length of array view returned by some value_contents functions Tom Tromey
2021-11-16 21:40   ` Simon Marchi

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=e2a8fe92-eed9-4549-1b73-ec8211cc2869@simark.ca \
    --to=simark@simark.ca \
    --cc=gdb-patches@sourceware.org \
    --cc=simon.marchi@efficios.com \
    --cc=tom@tromey.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