mirror of https://github.com/OpenRCT2/OpenRCT2.git
Initialise the pointer to bitcount_fn in a new early initialisation function
In order to avoid the overhead of checking whether the function pointer to bitcount's actual implementation has been initialised every time bitcount is called, initialise it at application startup.
This commit is contained in:
parent
bc101f4151
commit
46b6ff35a0
|
@ -196,6 +196,9 @@ bool platform_check_steam_overlay_attached();
|
|||
|
||||
datetime64 platform_get_datetime_now_utc();
|
||||
|
||||
// Called very early in the program before parsing commandline arguments.
|
||||
void core_init();
|
||||
|
||||
// Windows specific definitions
|
||||
#ifdef __WINDOWS__
|
||||
#ifndef WIN32_LEAN_AND_MEAN
|
||||
|
|
|
@ -51,6 +51,8 @@ utf8 _openrctDataDirectoryPath[MAX_PATH] = { 0 };
|
|||
*/
|
||||
int main(int argc, const char **argv)
|
||||
{
|
||||
core_init();
|
||||
|
||||
int run_game = cmdline_run(argv, argc);
|
||||
if (run_game == 1)
|
||||
{
|
||||
|
|
|
@ -782,3 +782,8 @@ uint8 platform_get_currency_value(const char *currCode) {
|
|||
|
||||
return CURRENCY_POUNDS;
|
||||
}
|
||||
|
||||
void core_init()
|
||||
{
|
||||
bitcount_init();
|
||||
}
|
||||
|
|
|
@ -61,6 +61,8 @@ int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine
|
|||
{
|
||||
_dllModule = hInstance;
|
||||
|
||||
core_init();
|
||||
|
||||
int argc;
|
||||
char ** argv = (char**)windows_get_command_line_args(&argc);
|
||||
int runGame = cmdline_run((const char **)argv, argc);
|
||||
|
@ -86,6 +88,8 @@ int main(int argc, char *argv[])
|
|||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
_dllModule = hInstance;
|
||||
|
||||
core_init();
|
||||
|
||||
int runGame = cmdline_run((const char **)argv, argc);
|
||||
if (runGame == 1) {
|
||||
openrct2_launch();
|
||||
|
@ -124,6 +128,8 @@ __declspec(dllexport) int StartOpenRCT(HINSTANCE hInstance, HINSTANCE hPrevInsta
|
|||
_dllModule = GetModuleHandleA(OPENRCT2_DLL_MODULE_NAME);
|
||||
}
|
||||
|
||||
core_init();
|
||||
|
||||
// argv = CommandLineToArgvA(lpCmdLine, &argc);
|
||||
argv = (char**)windows_get_command_line_args(&argc);
|
||||
runGame = cmdline_run((const char **)argv, argc);
|
||||
|
|
|
@ -253,13 +253,15 @@ static int bitcount_lut(int source)
|
|||
BitsSetTable256[source >> 24];
|
||||
}
|
||||
|
||||
static int(*bitcount_fn)(int);
|
||||
|
||||
void bitcount_init(void)
|
||||
{
|
||||
bitcount_fn = bitcount_available() ? bitcount_popcnt : bitcount_lut;
|
||||
}
|
||||
|
||||
int bitcount(int source)
|
||||
{
|
||||
static int(*bitcount_fn)(int);
|
||||
if(bitcount_fn == 0)
|
||||
{
|
||||
bitcount_fn = bitcount_available() ? bitcount_popcnt : bitcount_lut;
|
||||
}
|
||||
return bitcount_fn(source);
|
||||
}
|
||||
|
||||
|
|
|
@ -38,6 +38,7 @@ void path_end_with_separator(utf8 *path, size_t size);
|
|||
bool readentirefile(const utf8 *path, void **outBuffer, size_t *outLength);
|
||||
|
||||
int bitscanforward(int source);
|
||||
void bitcount_init(void);
|
||||
int bitcount(int source);
|
||||
bool strequals(const char *a, const char *b, int length, bool caseInsensitive);
|
||||
int strcicmp(char const *a, char const *b);
|
||||
|
|
Loading…
Reference in New Issue