From nobody Tue Apr 30 08:35:05 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.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 208.118.235.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 [208.118.235.17]) by mx.zohomail.com with SMTPS id 1544450966402263.2806076836207; Mon, 10 Dec 2018 06:09:26 -0800 (PST) Received: from localhost ([::1]:33021 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWMFN-00054T-Sv for importer@patchew.org; Mon, 10 Dec 2018 09:09:21 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:49164) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWMEJ-0004KS-Cw for qemu-devel@nongnu.org; Mon, 10 Dec 2018 09:08:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWMEG-0007mc-8X for qemu-devel@nongnu.org; Mon, 10 Dec 2018 09:08:15 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54876) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1gWMEF-0007m9-Qa for qemu-devel@nongnu.org; Mon, 10 Dec 2018 09:08:12 -0500 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 1F6B83084257; Mon, 10 Dec 2018 14:08:10 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-59.ams2.redhat.com [10.36.116.59]) by smtp.corp.redhat.com (Postfix) with ESMTP id 939DF5D738; Mon, 10 Dec 2018 14:08:09 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id C7A507530; Mon, 10 Dec 2018 15:08:08 +0100 (CET) From: Gerd Hoffmann To: qemu-devel@nongnu.org Date: Mon, 10 Dec 2018 15:08:08 +0100 Message-Id: <20181210140808.26794-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.40]); Mon, 10 Dec 2018 14:08:10 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PATCH] 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: felix.yzg@gmail.com, Gerd Hoffmann Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 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 --- 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