qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PULL 0/1] Input 20190111 patches
@ 2019-01-11 14:27 Gerd Hoffmann
  2019-01-11 14:27 ` [Qemu-devel] [PULL 1/1] input: avoid malloc for mouse events Gerd Hoffmann
  2019-01-14 11:41 ` [Qemu-devel] [PULL 0/1] Input 20190111 patches Peter Maydell
  0 siblings, 2 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2019-01-11 14:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

The following changes since commit a311f891abf3833c1e4c5a62a6e5b0f1b81f22c3:

  Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-4.0-pull-request' into staging (2019-01-10 17:49:54 +0000)

are available in the git repository at:

  git://git.kraxel.org/qemu tags/input-20190111-pull-request

for you to fetch changes up to 7a1b46e09504419a3aa867dba3bcf23db5d6d956:

  input: avoid malloc for mouse events (2019-01-11 11:57:17 +0100)

----------------------------------------------------------------
input: avoid malloc for mouse events

----------------------------------------------------------------

Gerd Hoffmann (1):
  input: avoid malloc for mouse events

 include/ui/input.h |  3 ---
 ui/input.c         | 68 +++++++++++++++++++++++++-----------------------------
 2 files changed, 31 insertions(+), 40 deletions(-)

-- 
2.9.3

^ permalink raw reply	[flat|nested] 3+ messages in thread

* [Qemu-devel] [PULL 1/1] input: avoid malloc for mouse events
  2019-01-11 14:27 [Qemu-devel] [PULL 0/1] Input 20190111 patches Gerd Hoffmann
@ 2019-01-11 14:27 ` Gerd Hoffmann
  2019-01-14 11:41 ` [Qemu-devel] [PULL 0/1] Input 20190111 patches Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Gerd Hoffmann @ 2019-01-11 14:27 UTC (permalink / raw)
  To: qemu-devel; +Cc: Gerd Hoffmann

There is no reason to allocate mouse events using malloc, we can
allcoate them from stack instead, save a few cpu cycles and make the
code more readable with c99 initializers.

Suggested-by: FelixYao <felix.yzg@gmail.com>
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Philippe Mathieu-Daudé <philmd@redhat.com>
Message-id: 20181210140808.26794-1-kraxel@redhat.com
---
 include/ui/input.h |  3 ---
 ui/input.c         | 68 +++++++++++++++++++++++++-----------------------------
 2 files changed, 31 insertions(+), 40 deletions(-)

diff --git a/include/ui/input.h b/include/ui/input.h
index 34ebc67c5a..8c8ccb999f 100644
--- a/include/ui/input.h
+++ b/include/ui/input.h
@@ -49,7 +49,6 @@ int qemu_input_key_value_to_scancode(const KeyValue *value, bool down,
                                      int *codes);
 int qemu_input_linux_to_qcode(unsigned int lnx);
 
-InputEvent *qemu_input_event_new_btn(InputButton btn, bool down);
 void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down);
 void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
                                uint32_t button_old, uint32_t button_new);
@@ -58,8 +57,6 @@ bool qemu_input_is_absolute(void);
 int qemu_input_scale_axis(int value,
                           int min_in, int max_in,
                           int min_out, int max_out);
-InputEvent *qemu_input_event_new_move(InputEventKind kind,
-                                      InputAxis axis, int value);
 void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value);
 void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value,
                           int min_in, int max_in);
diff --git a/ui/input.c b/ui/input.c
index 7c9a4109c4..f9d413fef9 100644
--- a/ui/input.c
+++ b/ui/input.c
@@ -458,22 +458,18 @@ void qemu_input_event_send_key_delay(uint32_t delay_ms)
     }
 }
 
-InputEvent *qemu_input_event_new_btn(InputButton btn, bool down)
-{
-    InputEvent *evt = g_new0(InputEvent, 1);
-    evt->u.btn.data = g_new0(InputBtnEvent, 1);
-    evt->type = INPUT_EVENT_KIND_BTN;
-    evt->u.btn.data->button = btn;
-    evt->u.btn.data->down = down;
-    return evt;
-}
-
 void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down)
 {
-    InputEvent *evt;
-    evt = qemu_input_event_new_btn(btn, down);
-    qemu_input_event_send(src, evt);
-    qapi_free_InputEvent(evt);
+    InputBtnEvent bevt = {
+        .button = btn,
+        .down = down,
+    };
+    InputEvent evt = {
+        .type = INPUT_EVENT_KIND_BTN,
+        .u.btn.data = &bevt,
+    };
+
+    qemu_input_event_send(src, &evt);
 }
 
 void qemu_input_update_buttons(QemuConsole *src, uint32_t *button_map,
@@ -513,37 +509,35 @@ int qemu_input_scale_axis(int value,
     return ((int64_t)value - min_in) * range_out / range_in + min_out;
 }
 
-InputEvent *qemu_input_event_new_move(InputEventKind kind,
-                                      InputAxis axis, int value)
-{
-    InputEvent *evt = g_new0(InputEvent, 1);
-    InputMoveEvent *move = g_new0(InputMoveEvent, 1);
-
-    evt->type = kind;
-    evt->u.rel.data = move; /* evt->u.rel is the same as evt->u.abs */
-    move->axis = axis;
-    move->value = value;
-    return evt;
-}
-
 void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value)
 {
-    InputEvent *evt;
-    evt = qemu_input_event_new_move(INPUT_EVENT_KIND_REL, axis, value);
-    qemu_input_event_send(src, evt);
-    qapi_free_InputEvent(evt);
+    InputMoveEvent move = {
+        .axis = axis,
+        .value = value,
+    };
+    InputEvent evt = {
+        .type = INPUT_EVENT_KIND_REL,
+        .u.rel.data = &move,
+    };
+
+    qemu_input_event_send(src, &evt);
 }
 
 void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value,
                           int min_in, int max_in)
 {
-    InputEvent *evt;
-    int scaled = qemu_input_scale_axis(value, min_in, max_in,
+    InputMoveEvent move = {
+        .axis = axis,
+        .value = qemu_input_scale_axis(value, min_in, max_in,
                                        INPUT_EVENT_ABS_MIN,
-                                       INPUT_EVENT_ABS_MAX);
-    evt = qemu_input_event_new_move(INPUT_EVENT_KIND_ABS, axis, scaled);
-    qemu_input_event_send(src, evt);
-    qapi_free_InputEvent(evt);
+                                       INPUT_EVENT_ABS_MAX),
+    };
+    InputEvent evt = {
+        .type = INPUT_EVENT_KIND_ABS,
+        .u.abs.data = &move,
+    };
+
+    qemu_input_event_send(src, &evt);
 }
 
 void qemu_input_check_mode_change(void)
-- 
2.9.3

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [Qemu-devel] [PULL 0/1] Input 20190111 patches
  2019-01-11 14:27 [Qemu-devel] [PULL 0/1] Input 20190111 patches Gerd Hoffmann
  2019-01-11 14:27 ` [Qemu-devel] [PULL 1/1] input: avoid malloc for mouse events Gerd Hoffmann
@ 2019-01-14 11:41 ` Peter Maydell
  1 sibling, 0 replies; 3+ messages in thread
From: Peter Maydell @ 2019-01-14 11:41 UTC (permalink / raw)
  To: Gerd Hoffmann; +Cc: QEMU Developers

On Fri, 11 Jan 2019 at 14:38, Gerd Hoffmann <kraxel@redhat.com> wrote:
>
> The following changes since commit a311f891abf3833c1e4c5a62a6e5b0f1b81f22c3:
>
>   Merge remote-tracking branch 'remotes/vivier2/tags/linux-user-for-4.0-pull-request' into staging (2019-01-10 17:49:54 +0000)
>
> are available in the git repository at:
>
>   git://git.kraxel.org/qemu tags/input-20190111-pull-request
>
> for you to fetch changes up to 7a1b46e09504419a3aa867dba3bcf23db5d6d956:
>
>   input: avoid malloc for mouse events (2019-01-11 11:57:17 +0100)
>
> ----------------------------------------------------------------
> input: avoid malloc for mouse events
>
> ----------------------------------------------------------------
>
> Gerd Hoffmann (1):
>   input: avoid malloc for mouse events
>
>  include/ui/input.h |  3 ---
>  ui/input.c         | 68 +++++++++++++++++++++++++-----------------------------
>  2 files changed, 31 insertions(+), 40 deletions(-)
>

Applied, thanks.

Please update the changelog at https://wiki.qemu.org/ChangeLog/4.0
for any user-visible changes.

-- PMM

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-01-14 11:41 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-01-11 14:27 [Qemu-devel] [PULL 0/1] Input 20190111 patches Gerd Hoffmann
2019-01-11 14:27 ` [Qemu-devel] [PULL 1/1] input: avoid malloc for mouse events Gerd Hoffmann
2019-01-14 11:41 ` [Qemu-devel] [PULL 0/1] Input 20190111 patches Peter Maydell

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).