[libsoup/carlosgc/message-feature-is-disabled: 1/2] soup-message: Use a hash set to store disabled features
- From: Carlos Garcia Campos <carlosgc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libsoup/carlosgc/message-feature-is-disabled: 1/2] soup-message: Use a hash set to store disabled features
- Date: Mon, 6 Jul 2020 09:45:03 +0000 (UTC)
commit c5813ff0a2ceb15f16cb1a25197a5e8611c7d2dd
Author: Carlos Garcia Campos <cgarcia igalia com>
Date: Mon Jul 6 11:08:19 2020 +0200
soup-message: Use a hash set to store disabled features
This way disabling the same feature twice doesn't add a new element to
the list.
libsoup/soup-cache.c | 6 ++++--
libsoup/soup-message-private.h | 4 ++--
libsoup/soup-message.c | 40 ++++++++++++++++++++++++++--------------
3 files changed, 32 insertions(+), 18 deletions(-)
---
diff --git a/libsoup/soup-cache.c b/libsoup/soup-cache.c
index 5d480244..f03999c4 100644
--- a/libsoup/soup-cache.c
+++ b/libsoup/soup-cache.c
@@ -1356,7 +1356,7 @@ soup_cache_generate_conditional_request (SoupCache *cache, SoupMessage *original
SoupURI *uri;
SoupCacheEntry *entry;
const char *last_modified, *etag;
- GSList *f;
+ GList *disabled_features, *f;
g_return_val_if_fail (SOUP_IS_CACHE (cache), NULL);
g_return_val_if_fail (SOUP_IS_MESSAGE (original), NULL);
@@ -1383,8 +1383,10 @@ soup_cache_generate_conditional_request (SoupCache *cache, SoupMessage *original
(SoupMessageHeadersForeachFunc)copy_headers,
msg->request_headers);
- for (f = soup_message_get_disabled_features (original); f; f = f->next)
+ disabled_features = soup_message_get_disabled_features (original);
+ for (f = disabled_features; f; f = f->next)
soup_message_disable_feature (msg, (GType) GPOINTER_TO_SIZE (f->data));
+ g_list_free (disabled_features);
if (last_modified)
soup_message_headers_append (msg->request_headers,
diff --git a/libsoup/soup-message-private.h b/libsoup/soup-message-private.h
index 0c6f5d97..59762e84 100644
--- a/libsoup/soup-message-private.h
+++ b/libsoup/soup-message-private.h
@@ -33,7 +33,7 @@ typedef struct {
SoupAuth *auth, *proxy_auth;
SoupConnection *connection;
- GSList *disabled_features;
+ GHashTable *disabled_features;
SoupURI *first_party;
SoupURI *site_for_cookies;
@@ -146,7 +146,7 @@ gboolean soup_message_disables_feature (SoupMessage *msg,
gboolean soup_message_disables_feature_by_type (SoupMessage *msg,
GType feature_type);
-GSList *soup_message_get_disabled_features (SoupMessage *msg);
+GList *soup_message_get_disabled_features (SoupMessage *msg);
void soup_message_set_https_status (SoupMessage *msg,
SoupConnection *conn);
diff --git a/libsoup/soup-message.c b/libsoup/soup-message.c
index 519972a8..1801c619 100644
--- a/libsoup/soup-message.c
+++ b/libsoup/soup-message.c
@@ -182,7 +182,7 @@ soup_message_finalize (GObject *object)
g_clear_object (&priv->auth);
g_clear_object (&priv->proxy_auth);
- g_slist_free (priv->disabled_features);
+ g_clear_pointer (&priv->disabled_features, g_hash_table_destroy);
g_clear_object (&priv->tls_certificate);
@@ -1899,50 +1899,62 @@ soup_message_disable_feature (SoupMessage *msg, GType feature_type)
priv = soup_message_get_instance_private (msg);
- priv->disabled_features = g_slist_prepend (priv->disabled_features,
- GSIZE_TO_POINTER (feature_type));
+ if (!priv->disabled_features)
+ priv->disabled_features = g_hash_table_new (g_direct_hash, g_direct_equal);
+
+ g_hash_table_add (priv->disabled_features, GSIZE_TO_POINTER (feature_type));
}
gboolean
soup_message_disables_feature (SoupMessage *msg, gpointer feature)
{
SoupMessagePrivate *priv;
- GSList *f;
+ GHashTableIter iter;
+ gpointer key;
g_return_val_if_fail (SOUP_IS_MESSAGE (msg), FALSE);
priv = soup_message_get_instance_private (msg);
- for (f = priv->disabled_features; f; f = f->next) {
- if (G_TYPE_CHECK_INSTANCE_TYPE (feature, (GType) GPOINTER_TO_SIZE (f->data)))
- return TRUE;
- }
- return FALSE;
+ if (!priv->disabled_features)
+ return FALSE;
+
+ g_hash_table_iter_init (&iter, priv->disabled_features);
+ while (g_hash_table_iter_next (&iter, &key, NULL)) {
+ if (G_TYPE_CHECK_INSTANCE_TYPE (feature, GPOINTER_TO_SIZE (key)))
+ return TRUE;
+ }
+ return FALSE;
}
gboolean
soup_message_disables_feature_by_type (SoupMessage *msg, GType feature_type)
{
SoupMessagePrivate *priv;
- GSList *f;
+ GHashTableIter iter;
+ gpointer key;
g_return_val_if_fail (SOUP_IS_MESSAGE (msg), FALSE);
priv = soup_message_get_instance_private (msg);
- for (f = priv->disabled_features; f; f = f->next) {
- if (g_type_is_a ((GType)GPOINTER_TO_SIZE (f->data), feature_type))
+ if (!priv->disabled_features)
+ return FALSE;
+
+ g_hash_table_iter_init (&iter, priv->disabled_features);
+ while (g_hash_table_iter_next (&iter, &key, NULL)) {
+ if (g_type_is_a (GPOINTER_TO_SIZE (key), feature_type))
return TRUE;
}
return FALSE;
}
-GSList *
+GList *
soup_message_get_disabled_features (SoupMessage *msg)
{
SoupMessagePrivate *priv = soup_message_get_instance_private (msg);
- return priv->disabled_features;
+ return priv->disabled_features ? g_hash_table_get_keys (priv->disabled_features) : NULL;
}
/**
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]