Skip to content

Commit 173bb3c

Browse files
committed
[lldb] Refactor GetDeviceSupportDirectoryNames and GetPlatformName (NFC)
Both functions are effectively returning a single string literal. Change the interface to return a llvm::StringRef instead of populating a vector of std::strings or returning a std::string respectively.
1 parent 011bf4f commit 173bb3c

10 files changed

+58
-98
lines changed

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -172,15 +172,10 @@ bool PlatformRemoteAppleBridge::GetSupportedArchitectureAtIndex(uint32_t idx,
172172
return false;
173173
}
174174

175-
176-
void PlatformRemoteAppleBridge::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
177-
{
178-
dirnames.clear();
179-
dirnames.push_back("BridgeOS DeviceSupport");
175+
llvm::StringRef PlatformRemoteAppleBridge::GetDeviceSupportDirectoryName() {
176+
return "BridgeOS DeviceSupport";
180177
}
181178

182-
std::string PlatformRemoteAppleBridge::GetPlatformName ()
183-
{
184-
return "BridgeOS.platform";
179+
llvm::StringRef PlatformRemoteAppleBridge::GetPlatformName() {
180+
return "BridgeOS.platform";
185181
}
186-

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleBridge.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ class PlatformRemoteAppleBridge : public PlatformRemoteDarwinDevice {
4848
lldb_private::ArchSpec &arch) override;
4949

5050
protected:
51-
52-
// lldb_private::PlatformRemoteDarwinDevice functions
53-
54-
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
55-
56-
std::string GetPlatformName () override;
51+
llvm::StringRef GetDeviceSupportDirectoryName() override;
52+
llvm::StringRef GetPlatformName() override;
5753
};
5854

5955
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEBRIDGE_H

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.cpp

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -223,15 +223,10 @@ bool PlatformRemoteAppleTV::GetSupportedArchitectureAtIndex(uint32_t idx,
223223
return false;
224224
}
225225

226-
227-
void PlatformRemoteAppleTV::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
228-
{
229-
dirnames.clear();
230-
dirnames.push_back("tvOS DeviceSupport");
226+
llvm::StringRef PlatformRemoteAppleTV::GetDeviceSupportDirectoryName() {
227+
return "tvOS DeviceSupport";
231228
}
232229

233-
std::string PlatformRemoteAppleTV::GetPlatformName ()
234-
{
235-
return "AppleTVOS.platform";
230+
llvm::StringRef PlatformRemoteAppleTV::GetPlatformName() {
231+
return "AppleTVOS.platform";
236232
}
237-

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleTV.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,8 @@ class PlatformRemoteAppleTV : public PlatformRemoteDarwinDevice {
4848
lldb_private::ArchSpec &arch) override;
4949

5050
protected:
51-
52-
// lldb_private::PlatformRemoteDarwinDevice functions
53-
54-
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
55-
56-
std::string GetPlatformName () override;
51+
llvm::StringRef GetDeviceSupportDirectoryName() override;
52+
llvm::StringRef GetPlatformName() override;
5753
};
5854

5955
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLETV_H

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.cpp

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,10 @@ bool PlatformRemoteAppleWatch::GetSupportedArchitectureAtIndex(uint32_t idx,
298298
return false;
299299
}
300300

301-
void PlatformRemoteAppleWatch::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
302-
{
303-
dirnames.clear();
304-
dirnames.push_back("watchOS DeviceSupport");
301+
llvm::StringRef PlatformRemoteAppleWatch::GetDeviceSupportDirectoryName() {
302+
return "watchOS DeviceSupport";
305303
}
306304

307-
std::string PlatformRemoteAppleWatch::GetPlatformName ()
308-
{
309-
return "WatchOS.platform";
305+
llvm::StringRef PlatformRemoteAppleWatch::GetPlatformName() {
306+
return "WatchOS.platform";
310307
}

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteAppleWatch.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,8 @@ class PlatformRemoteAppleWatch : public PlatformRemoteDarwinDevice {
5151
lldb_private::ArchSpec &arch) override;
5252

5353
protected:
54-
55-
// lldb_private::PlatformRemoteDarwinDevice functions
56-
57-
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
58-
59-
std::string GetPlatformName () override;
54+
llvm::StringRef GetDeviceSupportDirectoryName() override;
55+
llvm::StringRef GetPlatformName() override;
6056
};
6157

6258
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEAPPLEWATCH_H

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.cpp

Lines changed: 32 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -197,42 +197,36 @@ bool PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded() {
197197
}
198198
}
199199

200-
std::vector<std::string> device_support_dirnames;
201-
GetDeviceSupportDirectoryNames (device_support_dirnames);
202-
203-
for (std::string &dirname : device_support_dirnames)
204-
{
205-
const uint32_t num_installed = m_sdk_directory_infos.size();
206-
std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
207-
local_sdk_cache_str += dirname;
208-
FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
209-
FileSystem::Instance().Resolve(local_sdk_cache);
210-
if (FileSystem::Instance().Exists(local_sdk_cache)) {
211-
if (log) {
212-
LLDB_LOGF(
213-
log,
214-
"PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
215-
"searching %s for additional SDKs",
216-
local_sdk_cache.GetPath().c_str());
217-
}
218-
char path[PATH_MAX];
219-
if (local_sdk_cache.GetPath(path, sizeof(path))) {
220-
FileSystem::Instance().EnumerateDirectory(
221-
path, find_directories, find_files, find_other,
222-
GetContainedFilesIntoVectorOfStringsCallback,
223-
&m_sdk_directory_infos);
224-
const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
225-
// First try for an exact match of major, minor and update
226-
for (uint32_t i = num_installed; i < num_sdk_infos; ++i) {
227-
m_sdk_directory_infos[i].user_cached = true;
228-
if (log) {
229-
LLDB_LOGF(
230-
log,
231-
"PlatformRemoteDarwinDevice::"
232-
"UpdateSDKDirectoryInfosIfNeeded "
233-
"user SDK directory %s",
234-
m_sdk_directory_infos[i].directory.GetPath().c_str());
235-
}
200+
const uint32_t num_installed = m_sdk_directory_infos.size();
201+
llvm::StringRef dirname = GetDeviceSupportDirectoryName();
202+
std::string local_sdk_cache_str = "~/Library/Developer/Xcode/";
203+
local_sdk_cache_str += std::string(dirname);
204+
FileSpec local_sdk_cache(local_sdk_cache_str.c_str());
205+
FileSystem::Instance().Resolve(local_sdk_cache);
206+
if (FileSystem::Instance().Exists(local_sdk_cache)) {
207+
if (log) {
208+
LLDB_LOGF(
209+
log,
210+
"PlatformRemoteDarwinDevice::UpdateSDKDirectoryInfosIfNeeded "
211+
"searching %s for additional SDKs",
212+
local_sdk_cache.GetPath().c_str());
213+
}
214+
char path[PATH_MAX];
215+
if (local_sdk_cache.GetPath(path, sizeof(path))) {
216+
FileSystem::Instance().EnumerateDirectory(
217+
path, find_directories, find_files, find_other,
218+
GetContainedFilesIntoVectorOfStringsCallback,
219+
&m_sdk_directory_infos);
220+
const uint32_t num_sdk_infos = m_sdk_directory_infos.size();
221+
// First try for an exact match of major, minor and update
222+
for (uint32_t i = num_installed; i < num_sdk_infos; ++i) {
223+
m_sdk_directory_infos[i].user_cached = true;
224+
if (log) {
225+
LLDB_LOGF(log,
226+
"PlatformRemoteDarwinDevice::"
227+
"UpdateSDKDirectoryInfosIfNeeded "
228+
"user SDK directory %s",
229+
m_sdk_directory_infos[i].directory.GetPath().c_str());
236230
}
237231
}
238232
}
@@ -341,7 +335,8 @@ PlatformRemoteDarwinDevice::GetSDKDirectoryForLatestOSVersion() {
341335
}
342336

343337
const char *PlatformRemoteDarwinDevice::GetDeviceSupportDirectory() {
344-
std::string platform_dir = "/Platforms/" + GetPlatformName() + "/DeviceSupport";
338+
std::string platform_dir =
339+
("/Platforms/" + GetPlatformName() + "/DeviceSupport").str();
345340
if (m_device_support_directory.empty()) {
346341
if (FileSpec fspec = HostInfo::GetXcodeDeveloperDirectory()) {
347342
m_device_support_directory = fspec.GetPath();

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteDarwinDevice.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,8 @@ class PlatformRemoteDarwinDevice : public PlatformDarwin {
9797
// UINT32_MAX if that SDK not found.
9898
uint32_t GetSDKIndexBySDKDirectoryInfo(const SDKDirectoryInfo *sdk_info);
9999

100-
101-
virtual void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) = 0;
102-
103-
virtual std::string GetPlatformName () = 0;
100+
virtual llvm::StringRef GetDeviceSupportDirectoryName() = 0;
101+
virtual llvm::StringRef GetPlatformName() = 0;
104102

105103
private:
106104
PlatformRemoteDarwinDevice(const PlatformRemoteDarwinDevice &) = delete;

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -143,14 +143,10 @@ bool PlatformRemoteiOS::GetSupportedArchitectureAtIndex(uint32_t idx,
143143
return ARMGetSupportedArchitectureAtIndex(idx, arch);
144144
}
145145

146-
147-
void PlatformRemoteiOS::GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames)
148-
{
149-
dirnames.clear();
150-
dirnames.push_back("iOS DeviceSupport");
146+
llvm::StringRef PlatformRemoteiOS::GetDeviceSupportDirectoryName() {
147+
return "iOS DeviceSupport";
151148
}
152149

153-
std::string PlatformRemoteiOS::GetPlatformName ()
154-
{
155-
return "iPhoneOS.platform";
150+
llvm::StringRef PlatformRemoteiOS::GetPlatformName() {
151+
return "iPhoneOS.platform";
156152
}

lldb/source/Plugins/Platform/MacOSX/PlatformRemoteiOS.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,8 @@ class PlatformRemoteiOS : public PlatformRemoteDarwinDevice {
4747
lldb_private::ArchSpec &arch) override;
4848

4949
protected:
50-
51-
// lldb_private::PlatformRemoteDarwinDevice functions
52-
53-
void GetDeviceSupportDirectoryNames (std::vector<std::string> &dirnames) override;
54-
55-
std::string GetPlatformName () override;
50+
llvm::StringRef GetDeviceSupportDirectoryName() override;
51+
llvm::StringRef GetPlatformName() override;
5652
};
5753

5854
#endif // LLDB_SOURCE_PLUGINS_PLATFORM_MACOSX_PLATFORMREMOTEIOS_H

0 commit comments

Comments
 (0)