This is the mail archive of the gdb-patches@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: [PATCH v2 5/5] Eliminate make_cleanup_ui_file_delete / make ui_file a class hierarchy


On 01/24/2017 07:14 PM, Simon Marchi wrote:

> Oh, I guess it's because buf.string() returns a reference and not a
> string directly.  Otherwise, then I guess the compiler could have done
> some return value optimization (look at me, using words I don't
> understand).

I think that if buf.string() returned a copy instead of
a reference, then all the compiler could do in

  std::string foo ()
  {
    string_file buf;
    ...
    return buf.string_copy ();
  }

or:

  std::string foo ()
  {
    string_file buf;
    std::string tmp;

    tmp = buf.string_copy ();
    return tmp;
  }

is make sure to copy only once, from the buf straight
to the caller.  But there would still be one copy.  Unless
the compiler is smart enough to understand that buf is dying
at the end of the function and all buf destruction does is
destroy the string, so it could safely move the string 
out of buf before buf is destroyed.  But I don't think
compilers are that smart, unfortunately.

Thanks,
Pedro Alves


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]