From 4b22522ae0ea3686faa0edccc7ce23df1add013e Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 30 Apr 2019 19:36:40 +0200 Subject: [PATCH] We need faster string concatenation for performance-critical codepaths - this is being run every frame --- gfx/video_driver.c | 19 +++++++------------ libretro-common/include/string/stdstring.h | 8 ++++++++ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/gfx/video_driver.c b/gfx/video_driver.c index fd2069696f..ba4433b5de 100644 --- a/gfx/video_driver.c +++ b/gfx/video_driver.c @@ -2249,10 +2249,8 @@ void video_driver_set_title_buf(void) " ", info.library_name, sizeof(video_driver_title_buf)); - strlcat(video_driver_title_buf, - " ", sizeof(video_driver_title_buf)); - strlcat(video_driver_title_buf, - info.library_version, + string_concat(video_driver_title_buf, " "); + strlcat(video_driver_title_buf, info.library_version, sizeof(video_driver_title_buf)); } @@ -2422,8 +2420,7 @@ void video_driver_frame(const void *data, unsigned width, snprintf(video_info.fps_text, sizeof(video_info.fps_text), "FPS: %6.1f", last_fps); if (video_info.framecount_show) - strlcat(video_info.fps_text, - " || ", sizeof(video_info.fps_text)); + string_concat(video_info.fps_text, " || "); } if (video_info.framecount_show) @@ -2433,8 +2430,7 @@ void video_driver_frame(const void *data, unsigned width, sizeof(frames_text), "%s: %" PRIu64, msg_hash_to_str(MSG_FRAMES), (uint64_t)video_driver_frame_count); - strlcat(video_info.fps_text, - frames_text, sizeof(video_info.fps_text)); + string_concat(video_info.fps_text, frames_text); } if ((video_driver_frame_count % FPS_UPDATE_INTERVAL) == 0) @@ -2445,10 +2441,9 @@ void video_driver_frame(const void *data, unsigned width, if (!string_is_empty(video_info.fps_text)) { - strlcat(video_driver_window_title, - "|| ", sizeof(video_driver_window_title)); - strlcat(video_driver_window_title, - video_info.fps_text, sizeof(video_driver_window_title)); + string_concat(video_driver_window_title, "|| "); + string_concat(video_driver_window_title, + video_info.fps_text); } curr_time = new_time; diff --git a/libretro-common/include/string/stdstring.h b/libretro-common/include/string/stdstring.h index 7ddaa1ac14..d0d031711b 100644 --- a/libretro-common/include/string/stdstring.h +++ b/libretro-common/include/string/stdstring.h @@ -45,6 +45,14 @@ static INLINE bool string_is_equal(const char *a, const char *b) return (a && b) ? !strcmp(a, b) : false; } +static INLINE char *string_concat(char *dst, char *src) +{ + while (*dst) + dst++; + while ((*(dst)++ = *(src)++)); + return --dst; +} + #define STRLEN_CONST(x) ((sizeof((x))-1)) #define string_is_not_equal(a, b) !string_is_equal((a), (b))