diff options
author | Chris Robinson <[email protected]> | 2018-12-25 11:27:22 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2018-12-25 11:27:22 -0800 |
commit | 0314370eb58303bf0176b3222044bf27739ee5f5 (patch) | |
tree | e5f5dab4bbcde138d6ad885be1c6c3e5a027491c /Alc | |
parent | 208ea76922e8d69dc9ad93cbb0cf43634d9782a4 (diff) |
Cache the process binary path and name
Diffstat (limited to 'Alc')
-rw-r--r-- | Alc/alconfig.cpp | 22 | ||||
-rw-r--r-- | Alc/backends/pulseaudio.cpp | 2 | ||||
-rw-r--r-- | Alc/compat.h | 2 | ||||
-rw-r--r-- | Alc/helpers.cpp | 14 |
4 files changed, 22 insertions, 18 deletions
diff --git a/Alc/alconfig.cpp b/Alc/alconfig.cpp index 40131cc1..eecaf6fc 100644 --- a/Alc/alconfig.cpp +++ b/Alc/alconfig.cpp @@ -299,12 +299,12 @@ void ReadALConfig(void) noexcept LoadConfigFromFile(f); } - PathNamePair ppath = GetProcBinary(); - if(!ppath.path.empty()) + std::string ppath{GetProcBinary().path}; + if(!ppath.empty()) { - ppath.path += "\\alsoft.ini"; - TRACE("Loading config %s...\n", ppath.path.c_str()); - al::ifstream f{ppath.path.c_str()}; + ppath += "\\alsoft.ini"; + TRACE("Loading config %s...\n", ppath.c_str()); + al::ifstream f{ppath}; if(f.is_open()) LoadConfigFromFile(f); } @@ -422,14 +422,14 @@ void ReadALConfig(void) noexcept LoadConfigFromFile(f); } - PathNamePair ppath = GetProcBinary(); - if(!ppath.path.empty()) + std::string ppath{GetProcBinary().path}; + if(!ppath.empty()) { - if(ppath.path.back() != '/') ppath.path += "/alsoft.conf"; - else ppath.path += "alsoft.conf"; + if(ppath.back() != '/') ppath += "/alsoft.conf"; + else ppath += "alsoft.conf"; - TRACE("Loading config %s...\n", ppath.path.c_str()); - al::ifstream f{ppath.path}; + TRACE("Loading config %s...\n", ppath.c_str()); + al::ifstream f{ppath}; if(f.is_open()) LoadConfigFromFile(f); } diff --git a/Alc/backends/pulseaudio.cpp b/Alc/backends/pulseaudio.cpp index 8428b9d8..16e64cdf 100644 --- a/Alc/backends/pulseaudio.cpp +++ b/Alc/backends/pulseaudio.cpp @@ -406,7 +406,7 @@ pa_context *connect_context(pa_threaded_mainloop *loop, ALboolean silent) { const char *name{"OpenAL Soft"}; - PathNamePair binname = GetProcBinary(); + const PathNamePair &binname = GetProcBinary(); if(!binname.fname.empty()) name = binname.fname.c_str(); diff --git a/Alc/compat.h b/Alc/compat.h index 18ba8da9..dc652bca 100644 --- a/Alc/compat.h +++ b/Alc/compat.h @@ -223,7 +223,7 @@ using ifstream = std::ifstream; #include <string> struct PathNamePair { std::string path, fname; }; -PathNamePair GetProcBinary(void); +const PathNamePair &GetProcBinary(void); #ifdef HAVE_DYNLOAD void *LoadLib(const char *name); diff --git a/Alc/helpers.cpp b/Alc/helpers.cpp index beee4bff..2db544b8 100644 --- a/Alc/helpers.cpp +++ b/Alc/helpers.cpp @@ -310,9 +310,11 @@ void FPUCtl::leave() noexcept #ifdef _WIN32 -PathNamePair GetProcBinary() +const PathNamePair &GetProcBinary() { - PathNamePair ret; + static PathNamePair ret; + if(!ret.fname.empty() || !ret.path.empty()) + return ret; al::vector<WCHAR> fullpath(256); DWORD len; @@ -477,11 +479,13 @@ void SetRTPriority(void) #else -PathNamePair GetProcBinary() +const PathNamePair &GetProcBinary() { - PathNamePair ret; - al::vector<char> pathname; + static PathNamePair ret; + if(!ret.fname.empty() || !ret.path.empty()) + return ret; + al::vector<char> pathname; #ifdef __FreeBSD__ size_t pathlen; int mib[4] = { CTL_KERN, KERN_PROC, KERN_PROC_PATHNAME, -1 }; |