mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-09 20:29:10 +02:00
Prevent some allocations in environment lookups
In some places we'll still use the allocating non-const `operator[]` just because it would otherwise become pretty unreadable.
This commit is contained in:
@@ -40,11 +40,13 @@ constexpr char disable_watchdog_timer_env_var[] = "YABRIDGE_NO_WATCHDOG";
|
|||||||
constexpr char temp_dir_override_env_var[] = "YABRIDGE_TEMP_DIR";
|
constexpr char temp_dir_override_env_var[] = "YABRIDGE_TEMP_DIR";
|
||||||
|
|
||||||
fs::path get_temporary_directory() {
|
fs::path get_temporary_directory() {
|
||||||
bp::environment env = boost::this_process::environment();
|
const bp::environment env = boost::this_process::environment();
|
||||||
if (!env[temp_dir_override_env_var].empty()) {
|
if (const auto directory = env.find(temp_dir_override_env_var);
|
||||||
return env[temp_dir_override_env_var].to_string();
|
directory != env.end() && !directory->empty()) {
|
||||||
} else if (!env["XDG_RUNTIME_DIR"].empty()) {
|
return directory->to_string();
|
||||||
return env["XDG_RUNTIME_DIR"].to_string();
|
} else if (const auto directory = env.find("XDG_RUNTIME_DIR");
|
||||||
|
directory != env.end() && !directory->empty()) {
|
||||||
|
return directory->to_string();
|
||||||
} else {
|
} else {
|
||||||
return fs::temp_directory_path();
|
return fs::temp_directory_path();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -256,12 +256,13 @@ fs::path normalize_plugin_path(const fs::path& windows_library_path,
|
|||||||
|
|
||||||
std::variant<OverridenWinePrefix, fs::path, DefaultWinePrefix> find_wine_prefix(
|
std::variant<OverridenWinePrefix, fs::path, DefaultWinePrefix> find_wine_prefix(
|
||||||
fs::path windows_plugin_path) {
|
fs::path windows_plugin_path) {
|
||||||
bp::environment env = boost::this_process::environment();
|
const bp::environment env = boost::this_process::environment();
|
||||||
if (!env["WINEPREFIX"].empty()) {
|
if (const auto prefix = env.find("WINEPREFIX");
|
||||||
return OverridenWinePrefix{env["WINEPREFIX"].to_string()};
|
prefix != env.end() && !prefix->empty()) {
|
||||||
|
return OverridenWinePrefix{prefix->to_string()};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::optional<fs::path> dosdevices_dir = find_dominating_file(
|
const std::optional<fs::path> dosdevices_dir = find_dominating_file(
|
||||||
"dosdevices", windows_plugin_path, fs::is_directory);
|
"dosdevices", windows_plugin_path, fs::is_directory);
|
||||||
if (!dosdevices_dir) {
|
if (!dosdevices_dir) {
|
||||||
return DefaultWinePrefix{};
|
return DefaultWinePrefix{};
|
||||||
|
|||||||
Reference in New Issue
Block a user