Skip to content

Commit 1c8e68f

Browse files
bulbazordHoney Goyal
authored andcommitted
[lldb][NFCI] Remove FileAction::GetPath (llvm#170764)
This method puts strings into the ConstString pool and vends them as llvm::StringRefs. Most of the uses only require a `std::string` or a `const char *`. This can be achieved without wasting memory.
1 parent bd4c0b7 commit 1c8e68f

File tree

5 files changed

+29
-26
lines changed

5 files changed

+29
-26
lines changed

lldb/include/lldb/Host/FileAction.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ class FileAction {
3939

4040
int GetActionArgument() const { return m_arg; }
4141

42-
llvm::StringRef GetPath() const;
43-
4442
const FileSpec &GetFileSpec() const;
4543

4644
void Dump(Stream &stream) const;

lldb/source/Host/common/FileAction.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ void FileAction::Clear() {
2525
m_file_spec.Clear();
2626
}
2727

28-
llvm::StringRef FileAction::GetPath() const {
29-
return m_file_spec.GetPathAsConstString().AsCString();
30-
}
31-
3228
const FileSpec &FileAction::GetFileSpec() const { return m_file_spec; }
3329

3430
bool FileAction::Open(int fd, const FileSpec &file_spec, bool read,

lldb/source/Host/macosx/objcxx/Host.mm

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,20 +1013,29 @@ static Status LaunchProcessXPC(const char *exe_path,
10131013
xpc_dictionary_set_int64(message, LauncherXPCServicePosixspawnFlagsKey,
10141014
GetPosixspawnFlags(launch_info));
10151015
const FileAction *file_action = launch_info.GetFileActionForFD(STDIN_FILENO);
1016-
if (file_action && !file_action->GetPath().empty()) {
1016+
std::string file_action_path;
1017+
if (file_action)
1018+
file_action_path = file_action->GetFileSpec().GetPath();
1019+
1020+
if (!file_action_path.empty())
10171021
xpc_dictionary_set_string(message, LauncherXPCServiceStdInPathKeyKey,
1018-
file_action->GetPath().str().c_str());
1019-
}
1022+
file_action_path.c_str());
1023+
10201024
file_action = launch_info.GetFileActionForFD(STDOUT_FILENO);
1021-
if (file_action && !file_action->GetPath().empty()) {
1025+
if (file_action)
1026+
file_action_path = file_action->GetFileSpec().GetPath();
1027+
1028+
if (!file_action_path.empty())
10221029
xpc_dictionary_set_string(message, LauncherXPCServiceStdOutPathKeyKey,
1023-
file_action->GetPath().str().c_str());
1024-
}
1030+
file_action_path.c_str());
1031+
10251032
file_action = launch_info.GetFileActionForFD(STDERR_FILENO);
1026-
if (file_action && !file_action->GetPath().empty()) {
1033+
if (file_action)
1034+
file_action_path = file_action->GetFileSpec().GetPath();
1035+
1036+
if (!file_action_path.empty())
10271037
xpc_dictionary_set_string(message, LauncherXPCServiceStdErrPathKeyKey,
1028-
file_action->GetPath().str().c_str());
1029-
}
1038+
file_action_path.c_str());
10301039

10311040
xpc_object_t reply =
10321041
xpc_connection_send_message_with_reply_sync(conn, message);
@@ -1135,16 +1144,16 @@ static bool AddPosixSpawnFileAction(void *_file_actions, const FileAction *info,
11351144
if (oflag & O_CREAT)
11361145
mode = 0640;
11371146

1138-
error = Status(::posix_spawn_file_actions_addopen(
1139-
file_actions, info->GetFD(),
1140-
info->GetPath().str().c_str(), oflag, mode),
1141-
eErrorTypePOSIX);
1147+
const std::string file_path(info->GetFileSpec().GetPath());
1148+
error = Status(
1149+
::posix_spawn_file_actions_addopen(file_actions, info->GetFD(),
1150+
file_path.c_str(), oflag, mode),
1151+
eErrorTypePOSIX);
11421152
if (error.Fail())
11431153
LLDB_LOG(log,
11441154
"error: {0}, posix_spawn_file_actions_addopen (action={1}, "
11451155
"fd={2}, path='{3}', oflag={4}, mode={5})",
1146-
error, file_actions, info->GetFD(), info->GetPath(), oflag,
1147-
mode);
1156+
error, file_actions, info->GetFD(), file_path, oflag, mode);
11481157
}
11491158
break;
11501159
}

lldb/source/Host/posix/ProcessLauncherPosixFork.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,8 @@ struct ForkLaunchInfo {
229229
// End of code running in the child process.
230230

231231
ForkFileAction::ForkFileAction(const FileAction &act)
232-
: action(act.GetAction()), fd(act.GetFD()), path(act.GetPath().str()),
233-
arg(act.GetActionArgument()) {}
232+
: action(act.GetAction()), fd(act.GetFD()),
233+
path(act.GetFileSpec().GetPath()), arg(act.GetActionArgument()) {}
234234

235235
static std::vector<ForkFileAction>
236236
MakeForkActions(const ProcessLaunchInfo &info) {

lldb/source/Target/Target.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5145,17 +5145,17 @@ void TargetProperties::SetProcessLaunchInfo(
51455145
const FileAction *input_file_action =
51465146
launch_info.GetFileActionForFD(STDIN_FILENO);
51475147
if (input_file_action) {
5148-
SetStandardInputPath(input_file_action->GetPath());
5148+
SetStandardInputPath(input_file_action->GetFileSpec().GetPath());
51495149
}
51505150
const FileAction *output_file_action =
51515151
launch_info.GetFileActionForFD(STDOUT_FILENO);
51525152
if (output_file_action) {
5153-
SetStandardOutputPath(output_file_action->GetPath());
5153+
SetStandardOutputPath(output_file_action->GetFileSpec().GetPath());
51545154
}
51555155
const FileAction *error_file_action =
51565156
launch_info.GetFileActionForFD(STDERR_FILENO);
51575157
if (error_file_action) {
5158-
SetStandardErrorPath(error_file_action->GetPath());
5158+
SetStandardErrorPath(error_file_action->GetFileSpec().GetPath());
51595159
}
51605160
SetDetachOnError(launch_info.GetFlags().Test(lldb::eLaunchFlagDetachOnError));
51615161
SetDisableASLR(launch_info.GetFlags().Test(lldb::eLaunchFlagDisableASLR));

0 commit comments

Comments
 (0)