From nobody Fri Apr 19 20:03:51 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=redhat.com Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1547217402389857.5920149493478; Fri, 11 Jan 2019 06:36:42 -0800 (PST) Received: from localhost ([127.0.0.1]:38554 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghxvN-0003ji-B2 for importer@patchew.org; Fri, 11 Jan 2019 09:36:41 -0500 Received: from eggs.gnu.org ([209.51.188.92]:51151) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ghxm9-00056g-92 for qemu-devel@nongnu.org; Fri, 11 Jan 2019 09:27:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ghxm8-0008OQ-8J for qemu-devel@nongnu.org; Fri, 11 Jan 2019 09:27:09 -0500 Received: from mx1.redhat.com ([209.132.183.28]:42334) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ghxm8-0008O2-0E for qemu-devel@nongnu.org; Fri, 11 Jan 2019 09:27:08 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 33E8C37E60 for ; Fri, 11 Jan 2019 14:27:07 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-117-186.ams2.redhat.com [10.36.117.186]) by smtp.corp.redhat.com (Postfix) with ESMTP id 6F33C5F734; Fri, 11 Jan 2019 14:27:03 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 9F15C9AD3; Fri, 11 Jan 2019 15:27:02 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Fri, 11 Jan 2019 15:27:02 +0100 Message-Id: <20190111142702.25884-2-kraxel@redhat.com> In-Reply-To: <20190111142702.25884-1-kraxel@redhat.com> References: <20190111142702.25884-1-kraxel@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.29]); Fri, 11 Jan 2019 14:27:07 +0000 (UTC) Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 1/1] input: avoid malloc for mouse events X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Type: text/plain; charset="utf-8" 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 Signed-off-by: Gerd Hoffmann Reviewed-by: Markus Armbruster Reviewed-by: Philippe Mathieu-Daud=C3=A9 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 *valu= e, bool down, int *codes); int qemu_input_linux_to_qcode(unsigned int lnx); =20 -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_m= s) } } =20 -InputEvent *qemu_input_event_new_btn(InputButton btn, bool down) -{ - InputEvent *evt =3D g_new0(InputEvent, 1); - evt->u.btn.data =3D g_new0(InputBtnEvent, 1); - evt->type =3D INPUT_EVENT_KIND_BTN; - evt->u.btn.data->button =3D btn; - evt->u.btn.data->down =3D down; - return evt; -} - void qemu_input_queue_btn(QemuConsole *src, InputButton btn, bool down) { - InputEvent *evt; - evt =3D qemu_input_event_new_btn(btn, down); - qemu_input_event_send(src, evt); - qapi_free_InputEvent(evt); + InputBtnEvent bevt =3D { + .button =3D btn, + .down =3D down, + }; + InputEvent evt =3D { + .type =3D INPUT_EVENT_KIND_BTN, + .u.btn.data =3D &bevt, + }; + + qemu_input_event_send(src, &evt); } =20 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; } =20 -InputEvent *qemu_input_event_new_move(InputEventKind kind, - InputAxis axis, int value) -{ - InputEvent *evt =3D g_new0(InputEvent, 1); - InputMoveEvent *move =3D g_new0(InputMoveEvent, 1); - - evt->type =3D kind; - evt->u.rel.data =3D move; /* evt->u.rel is the same as evt->u.abs */ - move->axis =3D axis; - move->value =3D value; - return evt; -} - void qemu_input_queue_rel(QemuConsole *src, InputAxis axis, int value) { - InputEvent *evt; - evt =3D qemu_input_event_new_move(INPUT_EVENT_KIND_REL, axis, value); - qemu_input_event_send(src, evt); - qapi_free_InputEvent(evt); + InputMoveEvent move =3D { + .axis =3D axis, + .value =3D value, + }; + InputEvent evt =3D { + .type =3D INPUT_EVENT_KIND_REL, + .u.rel.data =3D &move, + }; + + qemu_input_event_send(src, &evt); } =20 void qemu_input_queue_abs(QemuConsole *src, InputAxis axis, int value, int min_in, int max_in) { - InputEvent *evt; - int scaled =3D qemu_input_scale_axis(value, min_in, max_in, + InputMoveEvent move =3D { + .axis =3D axis, + .value =3D qemu_input_scale_axis(value, min_in, max_in, INPUT_EVENT_ABS_MIN, - INPUT_EVENT_ABS_MAX); - evt =3D 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 =3D { + .type =3D INPUT_EVENT_KIND_ABS, + .u.abs.data =3D &move, + }; + + qemu_input_event_send(src, &evt); } =20 void qemu_input_check_mode_change(void) --=20 2.9.3