[retro-gtk] option: Rename current value from 'current' into 'value'
- From: Adrien Plazas <aplazas src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [retro-gtk] option: Rename current value from 'current' into 'value'
- Date: Sat, 5 May 2018 13:24:15 +0000 (UTC)
commit 66fd42d391f2d47e68774f0c526ce744facd2090
Author: Adrien Plazas <kekun plazas laposte net>
Date: Fri Nov 24 10:49:36 2017 +0100
option: Rename current value from 'current' into 'value'
Also store it as an index into the values array rather than a copy of
the string.
retro-gtk/retro-option.c | 30 ++++++++++++++++--------------
retro-gtk/retro-option.h | 8 ++++----
retro-gtk/retro-options.c | 4 ++--
3 files changed, 22 insertions(+), 20 deletions(-)
---
diff --git a/retro-gtk/retro-option.c b/retro-gtk/retro-option.c
index 525dd60..4c594be 100644
--- a/retro-gtk/retro-option.c
+++ b/retro-gtk/retro-option.c
@@ -8,7 +8,7 @@ struct _RetroOption
gchar *key;
gchar *description;
gchar **values;
- gchar *current;
+ gsize value;
};
G_DEFINE_TYPE (RetroOption, retro_option, G_TYPE_OBJECT)
@@ -33,7 +33,6 @@ retro_option_finalize (GObject *object)
g_free (self->key);
g_free (self->description);
g_strfreev (self->values);
- g_free (self->current);
G_OBJECT_CLASS (retro_option_parent_class)->finalize (object);
}
@@ -78,26 +77,31 @@ retro_option_get_values (RetroOption *self)
}
const gchar *
-retro_option_get_current (RetroOption *self)
+retro_option_get_value (RetroOption *self)
{
g_return_val_if_fail (RETRO_IS_OPTION (self), NULL);
- return self->current;
+ return self->values[self->value];
}
void
-retro_option_set_current (RetroOption *self,
- const gchar *current,
- GError **error)
+retro_option_set_value (RetroOption *self,
+ const gchar *value,
+ GError **error)
{
+ gsize i;
+
g_return_if_fail (RETRO_IS_OPTION (self));
- g_return_if_fail (current != NULL);
+ g_return_if_fail (value != NULL);
- g_message ("%s, %s", self->current, current);
- if (g_strcmp0 (self->current, current) == 0)
+ if (g_strcmp0 (self->values[self->value], value) == 0)
return;
- if (G_UNLIKELY (g_strv_contains ((const gchar *const *) self->values, current))) {
+ for (i = 0; self->values[i] != NULL; i++)
+ if (g_strcmp0 (self->values[i], value) == 0)
+ break;
+
+ if (G_UNLIKELY (self->values[i] == NULL)) {
g_set_error_literal (error,
RETRO_OPTION_ERROR,
RETRO_OPTION_ERROR_INVALID_VALUE,
@@ -106,8 +110,7 @@ retro_option_set_current (RetroOption *self,
return;
}
- g_free (self->current);
- self->current = g_strdup (current);
+ self->value = i;
}
RetroOption *
@@ -150,7 +153,6 @@ retro_option_new (const RetroVariable *variable,
self->description = g_strndup (variable->value,
description_separator - variable->value);
self->values = values;
- self->current = g_strdup (values[0]);
return self;
}
diff --git a/retro-gtk/retro-option.h b/retro-gtk/retro-option.h
index 38f650d..e1f1224 100644
--- a/retro-gtk/retro-option.h
+++ b/retro-gtk/retro-option.h
@@ -21,10 +21,10 @@ RetroOption *retro_option_new (const RetroVariable *variable,
const gchar *retro_option_get_key (RetroOption *self);
const gchar *retro_option_get_description (RetroOption *self);
const gchar **retro_option_get_values (RetroOption *self);
-const gchar *retro_option_get_current (RetroOption *self);
-void retro_option_set_current (RetroOption *self,
- const gchar *current,
- GError **error);
+const gchar *retro_option_get_value (RetroOption *self);
+void retro_option_set_value (RetroOption *self,
+ const gchar *value,
+ GError **error);
G_END_DECLS
diff --git a/retro-gtk/retro-options.c b/retro-gtk/retro-options.c
index f6a12c0..c8f29bf 100644
--- a/retro-gtk/retro-options.c
+++ b/retro-gtk/retro-options.c
@@ -82,7 +82,7 @@ retro_options_get_option_value (RetroOptions *self,
option = RETRO_OPTION (g_hash_table_lookup (self->options, key));
- return retro_option_get_current (option);
+ return retro_option_get_value (option);
}
void
@@ -99,7 +99,7 @@ retro_options_set_option_value (RetroOptions *self,
option = RETRO_OPTION (g_hash_table_lookup (self->options, key));
- retro_option_set_current (option, value, &tmp_error);
+ retro_option_set_value (option, value, &tmp_error);
if (G_UNLIKELY (tmp_error != NULL)) {
g_clear_error (&tmp_error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]