[llvm] r224953 - Remove unnecessary StringRef->std::string conversion.

Yaron Keren yaron.keren at gmail.com
Mon Dec 29 14:51:38 PST 2014


Could we assume that getMainExecutable result is a fixed constant while the
program runs, cache the result in a static std::string and return a
StringRef to the statc string?



2014-12-29 23:37 GMT+02:00 Alexey Samsonov <vonosmas at gmail.com>:

> On Mon, Dec 29, 2014 at 1:07 PM, Chandler Carruth <chandlerc at google.com>
> wrote:
>
>>
>> On Mon, Dec 29, 2014 at 12:59 PM, Alexey Samsonov <vonosmas at gmail.com>
>> wrote:
>>
>>> Author: samsonov
>>> Date: Mon Dec 29 14:59:02 2014
>>> New Revision: 224953
>>>
>>> URL: http://llvm.org/viewvc/llvm-project?rev=224953&view=rev
>>> Log:
>>> Remove unnecessary StringRef->std::string conversion.
>>>
>>> Modified:
>>>     llvm/trunk/lib/Support/Unix/Path.inc
>>>
>>> Modified: llvm/trunk/lib/Support/Unix/Path.inc
>>> URL:
>>> http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=224953&r1=224952&r2=224953&view=diff
>>>
>>> ==============================================================================
>>> --- llvm/trunk/lib/Support/Unix/Path.inc (original)
>>> +++ llvm/trunk/lib/Support/Unix/Path.inc Mon Dec 29 14:59:02 2014
>>> @@ -150,7 +150,7 @@ std::string getMainExecutable(const char
>>>        // /proc is not always mounted under Linux (chroot for example).
>>>        ssize_t len = readlink(aPath.str().c_str(), exe_path,
>>> sizeof(exe_path));
>>>        if (len >= 0)
>>> -          return StringRef(exe_path, len);
>>> +          return std::string(exe_path, len);
>>>
>>
>
>> Are you sure RVO can fire here? If not, this adds a std::string copy....
>>
>
> Implementation of StringRef -> std::string() conversion overaptor calls
> the same std::string(Data, Length) constructor.
>
>
> --
> Alexey Samsonov
> vonosmas at gmail.com
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141230/db2669bd/attachment.html>


More information about the llvm-commits mailing list