From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Gerd Hoffmann <kraxel@redhat.com>
Cc: qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH v2 2/5] keymap: use glib hash for kbd_layout_t
Date: Wed, 21 Feb 2018 14:38:00 +0000 [thread overview]
Message-ID: <20180221143800.GW17096@redhat.com> (raw)
In-Reply-To: <20180220150357.324-3-kraxel@redhat.com>
On Tue, Feb 20, 2018 at 04:03:54PM +0100, Gerd Hoffmann wrote:
> Drop home-grown lookup code, which is a strange mix of a lookup table
> and a list. Use standard glib hash instead.
>
> Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
> ---
> ui/keymaps.c | 79 +++++++++++++++++++++++++++------------------------------
> ui/trace-events | 2 +-
> 2 files changed, 38 insertions(+), 43 deletions(-)
>
> diff --git a/ui/keymaps.c b/ui/keymaps.c
> index 134958a197..bef1405576 100644
> --- a/ui/keymaps.c
> +++ b/ui/keymaps.c
> @@ -28,26 +28,28 @@
> #include "trace.h"
> #include "qemu/error-report.h"
>
> -#define MAX_NORMAL_KEYCODE 512
> -#define MAX_EXTRA_COUNT 256
> -
> struct key_range {
> int start;
> int end;
> struct key_range *next;
> };
>
> +struct keysym2code {
> + uint16_t keycode;
> +};
> +
> struct kbd_layout_t {
> - uint16_t keysym2keycode[MAX_NORMAL_KEYCODE];
> - struct {
> - int keysym;
> - uint16_t keycode;
> - } keysym2keycode_extra[MAX_EXTRA_COUNT];
> - int extra_count;
> + GHashTable *hash;
> struct key_range *keypad_range;
> struct key_range *numlock_range;
> };
>
> +static inline gpointer hashkey(int keysym)
> +{
> + intptr_t ptr = keysym;
> + return (gpointer)(ptr);
> +}
> +
> static int get_keysym(const name2keysym_t *table,
> const char *name)
> {
> @@ -91,23 +93,19 @@ static void add_to_key_range(struct key_range **krp, int code) {
> }
> }
>
> -static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k) {
> - if (keysym < MAX_NORMAL_KEYCODE) {
> - trace_keymap_add("normal", keysym, keycode, line);
> - k->keysym2keycode[keysym] = keycode;
> - } else {
> - if (k->extra_count >= MAX_EXTRA_COUNT) {
> - warn_report("Could not assign keysym %s (0x%x)"
> - " because of memory constraints.", line, keysym);
> - } else {
> - trace_keymap_add("extra", keysym, keycode, line);
> - k->keysym2keycode_extra[k->extra_count].
> - keysym = keysym;
> - k->keysym2keycode_extra[k->extra_count].
> - keycode = keycode;
> - k->extra_count++;
> - }
> +static void add_keysym(char *line, int keysym, int keycode, kbd_layout_t *k)
> +{
> + struct keysym2code *keysym2code;
> +
> + keysym2code = g_hash_table_lookup(k->hash, hashkey(keysym));
FYI, the glib2 GINT_TO_POINTER() macro is intended to cover this
usecase of storing integers as hash keys.
Regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
next prev parent reply other threads:[~2018-02-21 14:38 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-20 15:03 [Qemu-devel] [PATCH v2 0/5] keymap: support kbd layouts with multiple mappings for the same key Gerd Hoffmann
2018-02-20 15:03 ` [Qemu-devel] [PATCH v2 1/5] keymap: make struct kbd_layout_t private to ui/keymaps.c Gerd Hoffmann
2018-02-21 14:34 ` Daniel P. Berrangé
2018-02-20 15:03 ` [Qemu-devel] [PATCH v2 2/5] keymap: use glib hash for kbd_layout_t Gerd Hoffmann
2018-02-21 14:38 ` Daniel P. Berrangé [this message]
2018-02-20 15:03 ` [Qemu-devel] [PATCH v2 3/5] keymap: numpad keysyms and keycodes are fixed Gerd Hoffmann
2018-02-21 14:40 ` Daniel P. Berrangé
2018-02-20 15:03 ` [Qemu-devel] [PATCH v2 4/5] keymap: record multiple keysym -> keycode mappings Gerd Hoffmann
2018-02-21 14:42 ` Daniel P. Berrangé
2018-02-20 15:03 ` [Qemu-devel] [PATCH v2 5/5] keymap: consider modifier state when picking a mapping Gerd Hoffmann
2018-02-21 14:44 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20180221143800.GW17096@redhat.com \
--to=berrange@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).