diff options
| author | Nico Weber <nicolasweber@gmx.de> | 2019-08-07 17:00:19 +0000 | 
|---|---|---|
| committer | Nico Weber <nicolasweber@gmx.de> | 2019-08-07 17:00:19 +0000 | 
| commit | 1919317929a0f623f1bcfe1721e480556c9fdc62 (patch) | |
| tree | 70fe643df35fe0cb217fd0d6723b82231ad50a07 /llvm/lib/Support/Unix | |
| parent | 0e8dd4a80e74e9989fee27bdf13ea6d3589255f9 (diff) | |
| download | bcm5719-llvm-1919317929a0f623f1bcfe1721e480556c9fdc62.tar.gz bcm5719-llvm-1919317929a0f623f1bcfe1721e480556c9fdc62.zip  | |
Support: Remove needless allocation when getMainExecutable() calls readlink()
We built a StringRef from a string literal which we then converted to a
std::string to call c_str().  Just use a pointer to the string literal
instead of a StringRef.
No behavior change.
Differential Revision: https://reviews.llvm.org/D65890
llvm-svn: 368187
Diffstat (limited to 'llvm/lib/Support/Unix')
| -rw-r--r-- | llvm/lib/Support/Unix/Path.inc | 8 | 
1 files changed, 4 insertions, 4 deletions
diff --git a/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index dfd9389d2c6..bf277aa3069 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -186,12 +186,12 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {  #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) ||   \      defined(__minix) || defined(__DragonFly__) ||                              \      defined(__FreeBSD_kernel__) || defined(_AIX) -  StringRef curproc("/proc/curproc/file"); +  const char *curproc = "/proc/curproc/file";    char exe_path[PATH_MAX];    // /proc is not mounted by default under FreeBSD, but gives more accurate    // information than argv[0] when it is.    if (sys::fs::exists(curproc)) { -    ssize_t len = readlink(curproc.str().c_str(), exe_path, sizeof(exe_path)); +    ssize_t len = readlink(curproc, exe_path, sizeof(exe_path));      if (len > 0) {        // Null terminate the string for realpath. readlink never null        // terminates its output. @@ -205,10 +205,10 @@ std::string getMainExecutable(const char *argv0, void *MainAddr) {      return exe_path;  #elif defined(__linux__) || defined(__CYGWIN__)    char exe_path[MAXPATHLEN]; -  StringRef aPath("/proc/self/exe"); +  const char *aPath = "/proc/self/exe";    if (sys::fs::exists(aPath)) {      // /proc is not always mounted under Linux (chroot for example). -    ssize_t len = readlink(aPath.str().c_str(), exe_path, sizeof(exe_path)); +    ssize_t len = readlink(aPath, exe_path, sizeof(exe_path));      if (len < 0)        return "";  | 

