util/library: Use string_view instead of string

Slightly improves performance and reduces memory impact, as string data is not duplicated.
This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2020-11-05 06:25:49 +01:00
parent 032a3c6deb
commit 7e7ed80a9a
2 changed files with 7 additions and 7 deletions

View file

@ -73,12 +73,12 @@ util::library::~library()
#endif
}
void* util::library::load_symbol(std::string name)
void* util::library::load_symbol(std::string_view name)
{
#if defined(ST_WINDOWS)
return reinterpret_cast<void*>(GetProcAddress(reinterpret_cast<HMODULE>(_library), name.c_str()));
return reinterpret_cast<void*>(GetProcAddress(reinterpret_cast<HMODULE>(_library), name.data()));
#elif defined(ST_UNIX)
return reinterpret_cast<void*>(dlsym(_library, name.c_str()));
return reinterpret_cast<void*>(dlsym(_library, name.data()));
#endif
}
@ -101,7 +101,7 @@ std::shared_ptr<::util::library> util::library::load(std::filesystem::path file)
return ptr;
}
std::shared_ptr<::util::library> util::library::load(std::string name)
std::shared_ptr<::util::library> util::library::load(std::string_view name)
{
return load(std::filesystem::path(name));
}

View file

@ -21,7 +21,7 @@
#pragma once
#include <filesystem>
#include <memory>
#include <string>
#include <string_view>
namespace util {
class library {
@ -31,10 +31,10 @@ namespace util {
library(std::filesystem::path file);
~library();
void* load_symbol(std::string name);
void* load_symbol(std::string_view name);
static std::shared_ptr<::util::library> load(std::filesystem::path file);
static std::shared_ptr<::util::library> load(std::string name);
static std::shared_ptr<::util::library> load(std::string_view name);
};
} // namespace util