[Spice-devel] [PATCH spice-server 2/2] inputs-channel: Avoid some allocation using RedsState pointer
Jonathon Jongsma
jjongsma at redhat.com
Fri Dec 1 22:37:43 UTC 2017
I don't like this. It feels like it's being too clever and actually
makes things more confusing. The small benefit we get from not
allocating a small struct or two is definitely outweighed by the
disadvantages in my mind.
Jonathon
On Thu, 2017-11-30 at 12:03 +0000, Frediano Ziglio wrote:
> Signed-off-by: Frediano Ziglio <fziglio at redhat.com>
> ---
> server/inputs-channel.c | 21 +++++----------------
> 1 file changed, 5 insertions(+), 16 deletions(-)
>
> diff --git a/server/inputs-channel.c b/server/inputs-channel.c
> index 464ac21e..8e9eae49 100644
> --- a/server/inputs-channel.c
> +++ b/server/inputs-channel.c
> @@ -87,34 +87,23 @@ RedsState*
> spice_kbd_state_get_server(SpiceKbdState *dev)
> return dev->reds;
> }
>
> -struct SpiceMouseState {
> - int dummy;
> -};
> -
> -static SpiceMouseState* spice_mouse_state_new(void)
> +static SpiceMouseState* spice_mouse_state_new(RedsState *reds)
> {
> - return g_new0(SpiceMouseState, 1);
> + return (SpiceMouseState*) reds;
> }
>
> -struct SpiceTabletState {
> - RedsState *reds;
> -};
> -
> static SpiceTabletState* spice_tablet_state_new(RedsState* reds)
> {
> - SpiceTabletState *st = g_new0(SpiceTabletState, 1);
> - st->reds = reds;
> - return st;
> + return (SpiceTabletState*) reds;
> }
>
> static void spice_tablet_state_free(SpiceTabletState* st)
> {
> - g_free(st);
> }
>
> RedsState* spice_tablet_state_get_server(SpiceTabletState *st)
> {
> - return st->reds;
> + return (RedsState*) st;
> }
>
> typedef struct RedKeyModifiersPipeItem {
> @@ -631,7 +620,7 @@ int inputs_channel_set_mouse(InputsChannel
> *inputs, SpiceMouseInstance *mouse)
> return -1;
> }
> inputs->mouse = mouse;
> - inputs->mouse->st = spice_mouse_state_new();
> + inputs->mouse->st =
> spice_mouse_state_new(red_channel_get_server(RED_CHANNEL(inputs)));
> return 0;
> }
>
More information about the Spice-devel
mailing list