minor optimization of strncmp for literal comparison

This commit is contained in:
veclavtalica
2025-01-15 04:36:00 +03:00
parent 9d0a2cab81
commit 760515c551
2 changed files with 17 additions and 14 deletions

View File

@ -215,6 +215,7 @@ static void main_loop(void) {
game_object_tick();
input_state_update_postframe(&ctx.input);
/* TODO: make it works when ctx.ticks_per_second != 60 */
#ifdef TWN_FEATURE_PUSH_AUDIO
static uint8_t audio_buffer[(AUDIO_FREQUENCY / 60) * sizeof (float) * 2];
audio_callback(NULL, audio_buffer, sizeof audio_buffer);
@ -627,9 +628,9 @@ static bool initialize(void) {
if (!datum_font_filtering.ok) {
ctx.font_filtering = TEXT_FONT_FILTERING_DEFAULT;
} else {
if (SDL_strcmp(datum_font_filtering.u.s, "nearest") == 0) {
if (SDL_strncmp(datum_font_filtering.u.s, "nearest", sizeof "nearest") == 0) {
ctx.font_filtering = TEXTURE_FILTER_NEAREAST;
} else if (SDL_strcmp(datum_font_filtering.u.s, "linear") == 0) {
} else if (SDL_strncmp(datum_font_filtering.u.s, "linear", sizeof "nearest") == 0) {
ctx.font_filtering = TEXTURE_FILTER_LINEAR;
} else {
ctx.font_filtering = TEXT_FONT_FILTERING_DEFAULT;
@ -727,7 +728,7 @@ int enter_loop(int argc, char **argv) {
for (int i = 1; i < argc; ++i) {
/* override data directory */
if (SDL_strcmp(argv[i], "--data-dir") == 0) {
if (SDL_strncmp(argv[i], "--data-dir", sizeof "--data-dir" - 1) == 0) {
if (argv[i+1] == NULL || SDL_strncmp(argv[i+1], "--", 2) == 0) {
CRY("Data dir mount override failed.", "No arguments passed (expected 1).");
return EXIT_FAILURE;
@ -744,13 +745,13 @@ int enter_loop(int argc, char **argv) {
}
/* force debug mode */
if (SDL_strcmp(argv[i], "--debug") == 0) {
if (SDL_strncmp(argv[i], "--debug", sizeof "--debug" - 1) == 0) {
force_debug = true;
continue;
}
/* force release mode */
if (SDL_strcmp(argv[i], "--release") == 0) {
if (SDL_strncmp(argv[i], "--release", sizeof "--release" - 1) == 0) {
force_release = false;
continue;
}