Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

config_path(): return a reference #438

Merged
merged 1 commit into from
Aug 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions cpp/include/kvikio/cufile_config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@
namespace kvikio {
namespace detail {

[[nodiscard]] inline const std::string lookup_config_path()
[[nodiscard]] inline const char* lookup_config_path()
{
const char* env = std::getenv("CUFILE_ENV_PATH_JSON");
if (env != nullptr && std::filesystem::exists(env)) { return env; }
if (std::filesystem::exists("/etc/cufile.json")) { return "/etc/cufile.json"; }
Comment on lines 27 to 29
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

side question: could this be done once (e.g. init a local static var)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is done once, config_path() calls it to assign a static variable

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I assumed repeated calls because of the optimization.

return std::string();
return "";
}

} // namespace detail
Expand All @@ -39,7 +39,7 @@ namespace detail {
*
* @return The filepath to the cufile.json file or the empty string if it isn't found.
*/
[[nodiscard]] inline const std::string config_path()
[[nodiscard]] inline const std::string& config_path()
{
static const std::string ret = detail::lookup_config_path();
return ret;
Expand Down
Loading