Browse Source

Early out if setting a duplicate window title

Setting the window title is an expensive windowing operation, so short circuit it if possible.
Sam Lantinga 1 month ago
parent
commit
1ea99bc904
1 changed files with 8 additions and 1 deletions
  1. 8 1
      src/video/SDL_video.c

+ 8 - 1
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);