diff --git a/src/Input.c b/src/Input.c index 9044c8e1e..1c7ed08f7 100644 --- a/src/Input.c +++ b/src/Input.c @@ -140,13 +140,11 @@ bool KeyBind_IsPressed(KeyBind binding) { return Key_States[KeyBind_Keys[binding void KeyBind_Load(void) { Int32 i; - char nameBuffer[STRING_SIZE]; - String name = String_FromArray(nameBuffer); - for (i = 0; i < KeyBind_Count; i++) { - name.length = 0; - String_Format1(&name, "key-%c", KeyBind_Names[i]); + char nameBuffer[STRING_SIZE] = { 0 }; + String name = String_FromArray(nameBuffer); + String_Format1(&name, "key-%c", KeyBind_Names[i]); Key mapping = Options_GetEnum(name.buffer, KeyBind_Defaults[i], Key_Names, Key_Count); if (mapping != Key_Escape) KeyBind_Keys[i] = mapping; } @@ -157,13 +155,12 @@ void KeyBind_Save(void) { Int32 i; char nameBuffer[STRING_SIZE]; String name = String_FromArray(nameBuffer); - for (i = 0; i < KeyBind_Count; i++) { name.length = 0; - String_Format1(&name, "key-%c", KeyBind_Names[i]); + String_Format1(&name, "key-%c", KeyBind_Names[i]); String value = String_FromReadonly(Key_Names[KeyBind_Keys[i]]); - Options_Set(name.buffer, &value); + Options_SetString(&name, &value); } } @@ -328,7 +325,7 @@ void Hotkeys_UserRemovedHotkey(Key trigger, UInt8 flags) { String key = String_FromArray(keyBuffer); String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags); - Options_Set(key.buffer, NULL); + Options_SetString(&key, NULL); } void Hotkeys_UserAddedHotkey(Key trigger, UInt8 flags, bool moreInput, STRING_PURE String* text) { @@ -339,5 +336,5 @@ void Hotkeys_UserAddedHotkey(Key trigger, UInt8 flags, bool moreInput, STRING_PU String_Format2(&key, "hotkey-%c&%b", Key_Names[trigger], &flags); String_Format2(&value, "%t&%s", &moreInput, text); - Options_Set(key.buffer, &value); + Options_SetString(&key, &value); } diff --git a/src/Options.c b/src/Options.c index eb4cb1b39..70ac28134 100644 --- a/src/Options.c +++ b/src/Options.c @@ -138,6 +138,10 @@ void Options_SetInt(const char* keyRaw, Int32 value) { void Options_Set(const char* keyRaw, STRING_PURE String* value) { String key = String_FromReadonly(keyRaw); + Options_SetString(&key, value); +} + +void Options_SetString(STRING_PURE String* key, STRING_PURE String* value) { UInt32 i; if (value == NULL || value->buffer == NULL) { i = Options_Find(&key); diff --git a/src/Options.h b/src/Options.h index ff1f6480d..ccc4788cb 100644 --- a/src/Options.h +++ b/src/Options.h @@ -73,18 +73,19 @@ extern const char* FpsLimit_Names[FpsLimit_Count]; StringsBuffer Options_Keys; StringsBuffer Options_Values; -bool Options_HasAnyChanged(void); -void Options_Free(void); +NOINLINE_ bool Options_HasAnyChanged(void); +NOINLINE_ void Options_Free(void); -void Options_Get(const char* key, STRING_TRANSIENT String* value, const char* defValue); -Int32 Options_GetInt(const char* key, Int32 min, Int32 max, Int32 defValue); -bool Options_GetBool(const char* key, bool defValue); -Real32 Options_GetFloat(const char* key, Real32 min, Real32 max, Real32 defValue); -UInt32 Options_GetEnum(const char* key, UInt32 defValue, const char** names, UInt32 namesCount); +NOINLINE_ void Options_Get(const char* key, STRING_TRANSIENT String* value, const char* defValue); +NOINLINE_ Int32 Options_GetInt(const char* key, Int32 min, Int32 max, Int32 defValue); +NOINLINE_ bool Options_GetBool(const char* key, bool defValue); +NOINLINE_ Real32 Options_GetFloat(const char* key, Real32 min, Real32 max, Real32 defValue); +NOINLINE_ UInt32 Options_GetEnum(const char* key, UInt32 defValue, const char** names, UInt32 namesCount); -void Options_SetBool(const char* keyRaw, bool value); -void Options_SetInt(const char* keyRaw, Int32 value); -void Options_Set(const char* keyRaw, STRING_PURE String* value); -void Options_Load(void); -void Options_Save(void); +NOINLINE_ void Options_SetBool(const char* keyRaw, bool value); +NOINLINE_ void Options_SetInt(const char* keyRaw, Int32 value); +NOINLINE_ void Options_Set(const char* keyRaw, STRING_PURE String* value); +NOINLINE_ void Options_SetString(STRING_PURE String* key, STRING_PURE String* value); +NOINLINE_ void Options_Load(void); +NOINLINE_ void Options_Save(void); #endif diff --git a/src/Platform.c b/src/Platform.c index 0cb9eb486..02ae5a993 100644 --- a/src/Platform.c +++ b/src/Platform.c @@ -73,7 +73,7 @@ ReturnCode ReturnCode_SocketWouldBlock = EWOULDBLOCK; *---------------------------------------------------------Memory----------------------------------------------------------* *#########################################################################################################################*/ static void Platform_AllocFailed(const char* place) { - char logBuffer[STRING_SIZE + 20]; + char logBuffer[STRING_SIZE + 20] = { 0 }; String log = String_FromArray(logBuffer); String_Format1(&log, "Failed allocating memory for: %c", place); ErrorHandler_Fail(log.buffer);