comparison libpurple/status.c @ 23014:b0c9276bff93

Borrow a reference to a string instead of g_strdup'ing it. The PurpleStatus should ALWAYS be destroyed before the PurpleStatusType, so this should be ok. Yes, this is just one little string. But we copy every attribute for every PurpleStatus for every buddy on your buddylist--it adds up.
author Mark Doliner <mark@kingant.net>
date Tue, 20 May 2008 21:15:48 +0000
parents 21f1acb9090f
children 2567a386f3a8
comparison
equal deleted inserted replaced
23013:ba47ec8a2477 23014:b0c9276bff93
109 109
110 const char *title; 110 const char *title;
111 111
112 gboolean active; 112 gboolean active;
113 113
114 /*
115 * The current values of the attributes for this status. The
116 * key is a string containing the name of the attribute. It is
117 * a borrowed reference from the list of attrs in the
118 * PurpleStatusType. The value is a PurpleValue.
119 */
114 GHashTable *attr_values; 120 GHashTable *attr_values;
115 }; 121 };
116 122
117 typedef struct 123 typedef struct
118 { 124 {
561 567
562 status->type = status_type; 568 status->type = status_type;
563 status->presence = presence; 569 status->presence = presence;
564 570
565 status->attr_values = 571 status->attr_values =
566 g_hash_table_new_full(g_str_hash, g_str_equal, g_free, 572 g_hash_table_new_full(g_str_hash, g_str_equal, NULL,
567 (GDestroyNotify)purple_value_destroy); 573 (GDestroyNotify)purple_value_destroy);
568 574
569 for (l = purple_status_type_get_attrs(status_type); l != NULL; l = l->next) 575 for (l = purple_status_type_get_attrs(status_type); l != NULL; l = l->next)
570 { 576 {
571 PurpleStatusAttr *attr = (PurpleStatusAttr *)l->data; 577 PurpleStatusAttr *attr = (PurpleStatusAttr *)l->data;
572 PurpleValue *value = purple_status_attr_get_value(attr); 578 PurpleValue *value = purple_status_attr_get_value(attr);
573 PurpleValue *new_value = purple_value_dup(value); 579 PurpleValue *new_value = purple_value_dup(value);
574 580
575 g_hash_table_insert(status->attr_values, 581 g_hash_table_insert(status->attr_values,
576 g_strdup(purple_status_attr_get_id(attr)), 582 (char *)purple_status_attr_get_id(attr),
577 new_value); 583 new_value);
578 } 584 }
579 585
580 return status; 586 return status;
581 } 587 }