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

avoid many allocations? #50

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
14 changes: 7 additions & 7 deletions dependencies/interfaces/interfaces.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ namespace interfaces {
enum class interface_type { index, bruteforce };

template <typename ret, interface_type type>
ret* get_interface(std::string module_name, std::string interface_name) {
ret* get_interface(std::string_view module_name, std::string_view interface_name) {
using create_interface_fn = void* (*)(const char*, int*);
create_interface_fn fn = reinterpret_cast<create_interface_fn>(GetProcAddress(GetModuleHandle(module_name.c_str()), "CreateInterface"));
create_interface_fn fn = reinterpret_cast<create_interface_fn>(GetProcAddress(GetModuleHandle(module_name.data()), "CreateInterface"));

if (fn) {
void* result = nullptr;

switch (type) {
case interface_type::index:
result = fn(interface_name.c_str(), nullptr);
result = fn(interface_name.data(), nullptr);

break;
case interface_type::bruteforce:
Expand All @@ -48,7 +48,7 @@ namespace interfaces {
for (uint32_t i = 0; i <= 100; i++) {
memset((void*)buf, 0, sizeof buf);

result = fn(interface_name.c_str(), nullptr);
result = fn(interface_name.data(), nullptr);

if (result)
break;
Expand All @@ -58,9 +58,9 @@ namespace interfaces {
}

if (!result)
throw std::runtime_error(interface_name.c_str());
throw std::runtime_error(interface_name.data());

return reinterpret_cast<ret*>(result);
return static_cast<ret*>(result);
}

return reinterpret_cast<ret*>(nullptr);
Expand Down Expand Up @@ -93,4 +93,4 @@ namespace interfaces {
extern i_weapon_system* weapon_system;

bool initialize();
}
}