[Lldb-commits] [lldb] r123307 - /lldb/trunk/source/Host/common/Host.cpp

Stephen Wilson wilsons at start.ca
Wed Jan 12 15:04:23 PST 2011


Greg Clayton <gclayton at apple.com> writes:

> Quick possible optimization on the code below: I am guessing that
> readlink() returns a path that is already resolved? If so then passing
> true to the FileSpec constructor line:
>
> 	g_program_filespec = FileSpec(exe_path, true);
>
> will cause realpath() to be called on exe_path to try and resolve the
> path (which is typically meant for paths that might be symlinks, or
> "~/path/to/file", or "relative/path/to/file") which is probably
> redundant. We can pass false to this if the path is already resolved
> and avoid this:
>
> 	g_program_filespec = FileSpec(exe_path, false);
>
> Better yet, since the FileSpec constructor calls
> FileSpec::SetFile(...) anyway, this could just become:
>
> 	g_program_filespec.SetFile (exe_path, false);
>

Yes, absolutely.  The following has been tested and works fine.  I can
commit the patch in a few hours if you wish (running a bit short on time
ATM).


diff --git a/source/Host/common/Host.cpp b/source/Host/common/Host.cpp
index de0883c..a47a14c 100644
--- a/source/Host/common/Host.cpp
+++ b/source/Host/common/Host.cpp
@@ -624,7 +624,7 @@ Host::GetProgramFileSpec ()
         ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1);
         if (len > 0) {
             exe_path[len] = 0;
-            g_program_filespec = FileSpec(exe_path, true);
+            g_program_filespec.SetFile(exe_path, false);
         }
 #elif defined (__FreeBSD__)
         int exe_path_mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, getpid() };








More information about the lldb-commits mailing list