[retro-gtk] retro-core: Use GUINT_TO_POINTER() for controller ports
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] retro-core: Use GUINT_TO_POINTER() for controller ports
- Date: Mon, 3 Feb 2020 21:20:02 +0000 (UTC)
commit 8f0f419ecb6a7f080567587bca6aeb0e2e7e4e51
Author: Alexander Mikhaylenko <alexm gnome org>
Date: Sun Feb 2 16:17:04 2020 +0500
retro-core: Use GUINT_TO_POINTER() for controller ports
Don't heap-allocate uints to use as hashtable keys. Instead, use
GUINT_TO_POINTER().
Drop an extra pointer in retro_controller_iterator_next() to compensate.
retro-gtk/retro-controller-iterator.c | 4 ++--
retro-gtk/retro-controller-iterator.h | 2 +-
retro-gtk/retro-core.c | 17 +++++++----------
3 files changed, 10 insertions(+), 13 deletions(-)
---
diff --git a/retro-gtk/retro-controller-iterator.c b/retro-gtk/retro-controller-iterator.c
index b9e0a30..134742a 100644
--- a/retro-gtk/retro-controller-iterator.c
+++ b/retro-gtk/retro-controller-iterator.c
@@ -45,7 +45,7 @@ retro_controller_iterator_init (RetroControllerIterator *self)
*/
gboolean
retro_controller_iterator_next (RetroControllerIterator *self,
- guint **port,
+ guint *port,
RetroController **controller)
{
gpointer key, val;
@@ -56,7 +56,7 @@ retro_controller_iterator_next (RetroControllerIterator *self,
ret = g_hash_table_iter_next (&self->iterator, &key, &val);
if (port)
- *port = key;
+ *port = GPOINTER_TO_UINT (key);
if (controller)
*controller = val;
diff --git a/retro-gtk/retro-controller-iterator.h b/retro-gtk/retro-controller-iterator.h
index 4b8933a..127fa91 100644
--- a/retro-gtk/retro-controller-iterator.h
+++ b/retro-gtk/retro-controller-iterator.h
@@ -16,7 +16,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (RetroControllerIterator, retro_controller_iterator, RETRO, CONTROLLER_ITERATOR,
GObject)
gboolean retro_controller_iterator_next (RetroControllerIterator *self,
- guint **port,
+ guint *port,
RetroController **controller);
G_END_DECLS
diff --git a/retro-gtk/retro-core.c b/retro-gtk/retro-core.c
index 9b84a30..4a00d4d 100644
--- a/retro-gtk/retro-core.c
+++ b/retro-gtk/retro-core.c
@@ -589,8 +589,8 @@ retro_core_init (RetroCore *self)
self->option_overrides = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, g_free);
- self->controllers = g_hash_table_new_full (g_int_hash, g_int_equal,
- g_free, g_object_unref);
+ self->controllers = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL, g_object_unref);
self->main_loop = -1;
self->speed_rate = 1;
@@ -1450,7 +1450,7 @@ retro_core_boot (RetroCore *self,
{
RetroInit init;
RetroControllerIterator *controller_iterator;
- guint *port;
+ guint port;
RetroController *controller;
RetroControllerType controller_type;
GError *tmp_error = NULL;
@@ -1469,7 +1469,7 @@ retro_core_boot (RetroCore *self,
&port,
&controller)) {
controller_type = retro_controller_get_controller_type (controller);
- retro_core_set_controller_port_device (self, *port, controller_type);
+ retro_core_set_controller_port_device (self, port, controller_type);
}
g_object_unref (controller_iterator);
@@ -2132,7 +2132,7 @@ retro_core_get_controller_input_state (RetroCore *self,
controller_type = retro_input_get_controller_type (input) &
RETRO_CONTROLLER_TYPE_TYPE_MASK;
- controller = g_hash_table_lookup (self->controllers, &port);
+ controller = g_hash_table_lookup (self->controllers, GUINT_TO_POINTER (port));
if (controller != NULL &&
retro_controller_has_capability (controller, controller_type))
return retro_controller_get_input_state (controller, input);
@@ -2201,21 +2201,18 @@ retro_core_set_controller (RetroCore *self,
guint port,
RetroController *controller)
{
- guint *port_copy;
RetroControllerType controller_type;
g_return_if_fail (RETRO_IS_CORE (self));
if (RETRO_IS_CONTROLLER (controller)) {
- port_copy = g_new (guint, 1);
- *port_copy = port;
g_hash_table_insert (self->controllers,
- port_copy,
+ GUINT_TO_POINTER (port),
g_object_ref (controller));
controller_type = retro_controller_get_controller_type (controller);
}
else {
- g_hash_table_remove (self->controllers, &port);
+ g_hash_table_remove (self->controllers, GUINT_TO_POINTER (port));
controller_type = RETRO_CONTROLLER_TYPE_NONE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]