mirror of
https://github.com/robbert-vdh/yabridge.git
synced 2026-05-07 03:50:11 +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";
|
||||
|
||||
fs::path get_temporary_directory() {
|
||||
bp::environment env = boost::this_process::environment();
|
||||
if (!env[temp_dir_override_env_var].empty()) {
|
||||
return env[temp_dir_override_env_var].to_string();
|
||||
} else if (!env["XDG_RUNTIME_DIR"].empty()) {
|
||||
return env["XDG_RUNTIME_DIR"].to_string();
|
||||
const bp::environment env = boost::this_process::environment();
|
||||
if (const auto directory = env.find(temp_dir_override_env_var);
|
||||
directory != env.end() && !directory->empty()) {
|
||||
return directory->to_string();
|
||||
} else if (const auto directory = env.find("XDG_RUNTIME_DIR");
|
||||
directory != env.end() && !directory->empty()) {
|
||||
return directory->to_string();
|
||||
} else {
|
||||
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(
|
||||
fs::path windows_plugin_path) {
|
||||
bp::environment env = boost::this_process::environment();
|
||||
if (!env["WINEPREFIX"].empty()) {
|
||||
return OverridenWinePrefix{env["WINEPREFIX"].to_string()};
|
||||
const bp::environment env = boost::this_process::environment();
|
||||
if (const auto prefix = env.find("WINEPREFIX");
|
||||
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);
|
||||
if (!dosdevices_dir) {
|
||||
return DefaultWinePrefix{};
|
||||
|
||||
Reference in New Issue
Block a user