From 1ea99bc9048e6b5e6c4ce1eac516694c3e6db1d8 Mon Sep 17 00:00:00 2001 From: Sam Lantinga Date: Wed, 26 Feb 2025 17:10:41 -0800 Subject: [PATCH] Early out if setting a duplicate window title Setting the window title is an expensive windowing operation, so short circuit it if possible. --- src/video/SDL_video.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/video/SDL_video.c b/src/video/SDL_video.c index e4d642c867..3a400d8131 100644 --- a/src/video/SDL_video.c +++ b/src/video/SDL_video.c @@ -2767,9 +2767,16 @@ bool SDL_SetWindowTitle(SDL_Window *window, const char *title) if (title == window->title) { return true; } + if (!title) { + title = ""; + } + if (window->title && SDL_strcmp(title, window->title) == 0) { + return true; + } + SDL_free(window->title); - window->title = SDL_strdup(title ? title : ""); + window->title = SDL_strdup(title); if (_this->SetWindowTitle) { _this->SetWindowTitle(_this, window);