[PATCH 40/60] ui: minor code simplification

Marc-André Lureau posted 60 patches 2 weeks, 6 days ago
Maintainers: "Marc-André Lureau" <marcandre.lureau@redhat.com>, John Snow <jsnow@redhat.com>, Peter Maydell <peter.maydell@linaro.org>, Mauro Carvalho Chehab <mchehab+huawei@kernel.org>, Pierrick Bouvier <pierrick.bouvier@linaro.org>, Jan Kiszka <jan.kiszka@web.de>, Phil Dennis-Jordan <phil@philjordan.eu>, Richard Henderson <richard.henderson@linaro.org>, Helge Deller <deller@gmx.de>, "Philippe Mathieu-Daudé" <philmd@linaro.org>, Gerd Hoffmann <kraxel@redhat.com>, Mark Cave-Ayland <mark.cave-ayland@ilande.co.uk>, Samuel Tardieu <sam@rfc1149.net>, Igor Mitsyanko <i.mitsyanko@gmail.com>, "Hervé Poussineau" <hpoussin@reactos.org>, Aleksandar Rikalo <arikalo@gmail.com>, Laurent Vivier <laurent@vivier.eu>, Thomas Huth <th.huth+qemu@posteo.eu>, BALATON Zoltan <balaton@eik.bme.hu>, "Michael S. Tsirkin" <mst@redhat.com>, Stefano Garzarella <sgarzare@redhat.com>, "Alex Bennée" <alex.bennee@linaro.org>, Akihiko Odaki <odaki@rsg.ci.i.u-tokyo.ac.jp>, Dmitry Osipenko <dmitry.osipenko@collabora.com>, Dmitry Fleytman <dmitry.fleytman@gmail.com>, Stefano Stabellini <sstabellini@kernel.org>, Anthony PERARD <anthony@xenproject.org>, "Edgar E. Iglesias" <edgar.iglesias@gmail.com>, Alistair Francis <alistair@alistair23.me>, Alex Williamson <alex@shazbot.org>, "Cédric Le Goater" <clg@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, "Daniel P. Berrangé" <berrange@redhat.com>, Fabiano Rosas <farosas@suse.de>
[PATCH 40/60] ui: minor code simplification
Posted by Marc-André Lureau 2 weeks, 6 days ago
Remove the extra "info" variable and its initialization.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 ui/sdl2.c | 10 +++++-----
 ui/vnc.c  |  7 ++-----
 2 files changed, 7 insertions(+), 10 deletions(-)

diff --git a/ui/sdl2.c b/ui/sdl2.c
index aaaede56e0e..3ffb8acaff8 100644
--- a/ui/sdl2.c
+++ b/ui/sdl2.c
@@ -600,11 +600,11 @@ static void handle_windowevent(SDL_Event *ev)
     switch (ev->window.event) {
     case SDL_WINDOWEVENT_RESIZED:
         {
-            QemuUIInfo info;
-            memset(&info, 0, sizeof(info));
-            info.width = ev->window.data1;
-            info.height = ev->window.data2;
-            dpy_set_ui_info(scon->dcl.con, &info, true);
+            dpy_set_ui_info(scon->dcl.con,
+                &(QemuUIInfo) {
+                    .width = ev->window.data1,
+                    .height = ev->window.data2,
+                }, true);
         }
         sdl2_redraw(scon);
         break;
diff --git a/ui/vnc.c b/ui/vnc.c
index 4aa446a48d7..87ec3e6d799 100644
--- a/ui/vnc.c
+++ b/ui/vnc.c
@@ -2638,11 +2638,8 @@ static int protocol_client_msg(VncState *vs, uint8_t *data, size_t len)
 
         trace_vnc_msg_client_set_desktop_size(vs, vs->ioc, w, h, screens);
         if (dpy_ui_info_supported(vs->vd->dcl.con)) {
-            QemuUIInfo info;
-            memset(&info, 0, sizeof(info));
-            info.width = w;
-            info.height = h;
-            dpy_set_ui_info(vs->vd->dcl.con, &info, false);
+            dpy_set_ui_info(vs->vd->dcl.con,
+                &(QemuUIInfo){ .width = w, .height = h }, false);
             vnc_desktop_resize_ext(vs, 4 /* Request forwarded */);
         } else {
             vnc_desktop_resize_ext(vs, 3 /* Invalid screen layout */);

-- 
2.53.0


Re: [PATCH 40/60] ui: minor code simplification
Posted by Daniel P. Berrangé 1 week, 6 days ago
On Tue, Mar 17, 2026 at 12:50:54PM +0400, Marc-André Lureau wrote:
> Remove the extra "info" variable and its initialization.
> 
> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
> ---
>  ui/sdl2.c | 10 +++++-----
>  ui/vnc.c  |  7 ++-----
>  2 files changed, 7 insertions(+), 10 deletions(-)
> 
> diff --git a/ui/sdl2.c b/ui/sdl2.c
> index aaaede56e0e..3ffb8acaff8 100644
> --- a/ui/sdl2.c
> +++ b/ui/sdl2.c
> @@ -600,11 +600,11 @@ static void handle_windowevent(SDL_Event *ev)
>      switch (ev->window.event) {
>      case SDL_WINDOWEVENT_RESIZED:
>          {
> -            QemuUIInfo info;
> -            memset(&info, 0, sizeof(info));
> -            info.width = ev->window.data1;
> -            info.height = ev->window.data2;
> -            dpy_set_ui_info(scon->dcl.con, &info, true);
> +            dpy_set_ui_info(scon->dcl.con,
> +                &(QemuUIInfo) {
> +                    .width = ev->window.data1,
> +                    .height = ev->window.data2,
> +                }, true);

I find this new code less readable than the original. The compiler
optimizer can remove uneccessary variables in this way.

I would, however, suggest removing the memset and doing

             QemuUIInfo info = { .width = ev->window.data1,
                                 .height = ev->window.data2 };
             dpy_set_ui_info(scon->dcl.con, &info, true);

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|


Re: [PATCH 40/60] ui: minor code simplification
Posted by Philippe Mathieu-Daudé 5 days, 17 hours ago
On 24/3/26 15:30, Daniel P. Berrangé wrote:
> On Tue, Mar 17, 2026 at 12:50:54PM +0400, Marc-André Lureau wrote:
>> Remove the extra "info" variable and its initialization.
>>
>> Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
>> ---
>>   ui/sdl2.c | 10 +++++-----
>>   ui/vnc.c  |  7 ++-----
>>   2 files changed, 7 insertions(+), 10 deletions(-)
>>
>> diff --git a/ui/sdl2.c b/ui/sdl2.c
>> index aaaede56e0e..3ffb8acaff8 100644
>> --- a/ui/sdl2.c
>> +++ b/ui/sdl2.c
>> @@ -600,11 +600,11 @@ static void handle_windowevent(SDL_Event *ev)
>>       switch (ev->window.event) {
>>       case SDL_WINDOWEVENT_RESIZED:
>>           {
>> -            QemuUIInfo info;
>> -            memset(&info, 0, sizeof(info));
>> -            info.width = ev->window.data1;
>> -            info.height = ev->window.data2;
>> -            dpy_set_ui_info(scon->dcl.con, &info, true);
>> +            dpy_set_ui_info(scon->dcl.con,
>> +                &(QemuUIInfo) {
>> +                    .width = ev->window.data1,
>> +                    .height = ev->window.data2,
>> +                }, true);
> 
> I find this new code less readable than the original. The compiler
> optimizer can remove uneccessary variables in this way.
> 
> I would, however, suggest removing the memset and doing
> 
>               QemuUIInfo info = { .width = ev->window.data1,
>                                   .height = ev->window.data2 };
>               dpy_set_ui_info(scon->dcl.con, &info, true);

Using suggestion:

Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org>