aboutsummaryrefslogtreecommitdiffstats
path: root/addressbook
diff options
context:
space:
mode:
authorJeffrey Stedfast <fejj@ximian.com>2001-07-13 05:37:52 +0800
committerJeffrey Stedfast <fejj@src.gnome.org>2001-07-13 05:37:52 +0800
commit827c51c7ba8e18748c7518869187e401e95ee3d5 (patch)
tree925577b305774baa524d6cb3cb659a4bed39b84c /addressbook
parent89341d76ec219b14431fb3778a9d22df3079ffda (diff)
downloadgsoc2013-evolution-827c51c7ba8e18748c7518869187e401e95ee3d5.tar.gz
gsoc2013-evolution-827c51c7ba8e18748c7518869187e401e95ee3d5.tar.zst
gsoc2013-evolution-827c51c7ba8e18748c7518869187e401e95ee3d5.zip
Optimized the same way I optimized g_strsplit. If you use a GPtrArray
2001-07-12 Jeffrey Stedfast <fejj@ximian.com> * backend/ebook/e-destination.c (e_destination_importv): Optimized the same way I optimized g_strsplit. If you use a GPtrArray instead of a linked list, you save yourself from having to iterate through the list an extra 3 times. (e_destination_xml_decode): Do NOT, I repeat: do NOT! e_utf8_xml1_decode something which is already in UTF-8 or you'll corrupt it!! I smack thee who hath done this evil deed! svn path=/trunk/; revision=11069
Diffstat (limited to 'addressbook')
-rw-r--r--addressbook/ChangeLog16
-rw-r--r--addressbook/backend/ebook/e-destination.c157
2 files changed, 76 insertions, 97 deletions
diff --git a/addressbook/ChangeLog b/addressbook/ChangeLog
index 69fa2e9069..57c1547f01 100644
--- a/addressbook/ChangeLog
+++ b/addressbook/ChangeLog
@@ -1,8 +1,18 @@
+2001-07-12 Jeffrey Stedfast <fejj@ximian.com>
+
+ * backend/ebook/e-destination.c (e_destination_importv): Optimized
+ the same way I optimized g_strsplit. If you use a GPtrArray
+ instead of a linked list, you save yourself from having to iterate
+ through the list an extra 3 times.
+ (e_destination_xml_decode): Do NOT, I repeat: do NOT!
+ e_utf8_xml1_decode something which is already in UTF-8 or you'll
+ corrupt it!! I smack thee who hath done this evil deed!
+
2001-07-12 Iain Holmes <iain@ximian.com>
- * backend/e-book/evolution-vcard-importer.c (support_format_fn): Check
- for no extension. Actually same as Jason's fix below :) but also check
- the file contents.
+ * backend/e-book/evolution-vcard-importer.c (support_format_fn):
+ Check for no extension. Actually same as Jason's fix below :) but
+ also check the file contents.
2001-07-12 JP Rosevear <jpr@ximian.com>
diff --git a/addressbook/backend/ebook/e-destination.c b/addressbook/backend/ebook/e-destination.c
index c05b15b380..2e1f6c802e 100644
--- a/addressbook/backend/ebook/e-destination.c
+++ b/addressbook/backend/ebook/e-destination.c
@@ -489,47 +489,43 @@ const gchar *
e_destination_get_address (const EDestination *dest)
{
struct _EDestinationPrivate *priv;
-
+
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), NULL);
-
+
priv = (struct _EDestinationPrivate *)dest->priv; /* cast out const */
if (priv->addr == NULL) {
-
if (e_destination_is_evolution_list (dest)) {
-
gchar **strv = g_new0 (gchar *, g_list_length (priv->list_dests) + 1);
gint i = 0;
GList *iter = dest->priv->list_dests;
-
+
while (iter) {
EDestination *list_dest = E_DESTINATION (iter->data);
- if (! e_destination_is_empty (list_dest)) {
- strv[i] = (gchar *) e_destination_get_address (list_dest);
- ++i;
+ if (!e_destination_is_empty (list_dest)) {
+ strv[i++] = (gchar *) e_destination_get_address (list_dest);
}
iter = g_list_next (iter);
}
-
+
priv->addr = g_strjoinv (", ", strv);
-
+
g_message ("List address is [%s]", priv->addr);
-
+
g_free (strv);
-
} else {
-
const gchar *name = e_destination_get_name (dest);
const gchar *email = e_destination_get_email (dest);
-
- if (email) { /* If this isn't set, we return NULL */
-
+
+ /* If this isn't set, we return NULL */
+ if (email) {
if (name) {
-
- gchar *lt = strchr (name, '<');
+ /* uhm, yea... this'll work. NOT!!! */
+ /* what about ','? or any of the other chars that require quoting?? */
+ const gchar *lt = strchr (name, '<');
gchar *namecpy = lt ? g_strndup (name, lt-name) : g_strdup (name);
gboolean needs_quotes = (strchr (namecpy, '.') != NULL);
-
+
g_strstrip (namecpy);
priv->addr = g_strdup_printf ("%s%s%s <%s>",
@@ -538,18 +534,12 @@ e_destination_get_address (const EDestination *dest)
needs_quotes ? "\"" : "",
email);
g_free (namecpy);
-
} else {
-
priv->addr = g_strdup (email);
-
}
-
} else {
-
/* Just use the name, which is the best we can do. */
priv->addr = g_strdup (name);
-
}
}
}
@@ -616,26 +606,29 @@ e_destination_get_address_textv (EDestination **destv)
gint i, j, len = 0;
gchar **strv;
gchar *str;
+
g_return_val_if_fail (destv, NULL);
+ /* FIXME: please tell me this is only for assertion
+ reasons. If this is considered to be ok behavior then you
+ shouldn't use g_return's. Just a reminder ;-) */
while (destv[len]) {
g_return_val_if_fail (E_IS_DESTINATION (destv[len]), NULL);
++len;
}
-
+
strv = g_new0 (gchar *, len+1);
- for (i = 0, j = 0; destv[i]; ++i) {
-
- if (! e_destination_is_empty (destv[i])) {
+ for (i = 0, j = 0; destv[i]; i++) {
+ if (!e_destination_is_empty (destv[i])) {
const gchar *addr = e_destination_get_address (destv[i]);
strv[j++] = addr ? (gchar *) addr : "";
}
}
-
+
str = g_strjoinv (", ", strv);
-
+
g_free (strv);
-
+
return str;
}
@@ -654,14 +647,12 @@ e_destination_xml_encode (const EDestination *dest)
xmlNewTextChild (dest_node, NULL, "name", str);
if (! e_destination_is_evolution_list (dest)) {
-
str = e_destination_get_email (dest);
if (str)
xmlNewTextChild (dest_node, NULL, "email", str);
-
} else {
-
GList *iter = dest->priv->list_dests;
+
while (iter) {
EDestination *list_dest = E_DESTINATION (iter->data);
xmlNodePtr list_node = xmlNewNode (NULL, "list_entry");
@@ -704,97 +695,82 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
gboolean is_list = FALSE;
gchar *tmp;
GList *list_dests = NULL;
-
+
g_return_val_if_fail (dest && E_IS_DESTINATION (dest), FALSE);
g_return_val_if_fail (node != NULL, FALSE);
-
+
if (strcmp (node->name, "destination"))
return FALSE;
-
+
tmp = xmlGetProp (node, "html_mail");
if (tmp) {
html_mail = !strcmp (tmp, "yes");
xmlFree (tmp);
}
-
+
tmp = xmlGetProp (node, "is_list");
if (tmp) {
is_list = !strcmp (tmp, "yes");
xmlFree (tmp);
}
-
+
node = node->xmlChildrenNode;
while (node) {
-
if (!strcmp (node->name, "name")) {
-
tmp = xmlNodeGetContent (node);
g_free (name);
- name = e_utf8_xml1_decode (tmp);
+ name = g_strdup (tmp);
xmlFree (tmp);
-
} else if (!is_list && !strcmp (node->name, "email")) {
-
tmp = xmlNodeGetContent (node);
g_free (email);
- email = e_utf8_xml1_decode (tmp);
+ email = g_strdup (email);
xmlFree (tmp);
-
} else if (is_list && !strcmp (node->name, "list_entry")) {
-
xmlNodePtr subnode = node->xmlChildrenNode;
gchar *list_name = NULL, *list_email = NULL;
while (subnode) {
-
if (!strcmp (subnode->name, "name")) {
-
tmp = xmlNodeGetContent (subnode);
g_free (list_name);
- list_name = e_utf8_xml1_decode (tmp);
+ list_name = g_strdup (tmp);
xmlFree (tmp);
-
} else if (!strcmp (subnode->name, "email")) {
-
tmp = xmlNodeGetContent (subnode);
g_free (list_email);
- list_email = e_utf8_xml1_decode (tmp);
+ list_email = g_strdup (tmp);
xmlFree (tmp);
-
}
-
+
subnode = subnode->next;
}
-
+
if (list_name || list_email) {
EDestination *list_dest = e_destination_new ();
if (list_name)
e_destination_set_name (list_dest, list_name);
if (list_email)
e_destination_set_email (list_dest, list_email);
-
- list_dests = g_list_append (list_dests, list_dest);
+ list_dests = g_list_append (list_dests, list_dest);
}
-
} else if (!strcmp (node->name, "card_uri")) {
-
tmp = xmlNodeGetContent (node);
g_free (card_uri);
- card_uri = e_utf8_xml1_decode (tmp);
+ card_uri = g_strdup (tmp);
xmlFree (tmp);
-
+
tmp = xmlGetProp (node, "email_num");
email_num = atoi (tmp);
xmlFree (tmp);
-
}
-
+
node = node->next;
}
-
+
e_destination_clear (dest);
-
+
if (name)
e_destination_set_name (dest, name);
if (email)
@@ -803,7 +779,7 @@ e_destination_xml_decode (EDestination *dest, xmlNodePtr node)
e_destination_set_card_uri (dest, card_uri, email_num);
if (list_dests)
dest->priv->list_dests = list_dests;
-
+
return TRUE;
}
@@ -928,53 +904,46 @@ e_destination_exportv (EDestination **destv)
EDestination **
e_destination_importv (const gchar *str)
{
- GList *dest_list = NULL, *iter;
+ GPtrArray *dest_array = NULL;
xmlDocPtr destv_doc;
xmlNodePtr node;
EDestination **destv = NULL;
- gint N;
-
- if (! (str && *str))
+
+ if (!(str && *str))
return NULL;
-
+
destv_doc = xmlParseMemory ((gchar *)str, strlen (str));
node = destv_doc->xmlRootNode;
-
+
if (strcmp (node->name, "destinations"))
goto finished;
-
+
node = node->xmlChildrenNode;
+ dest_array = g_ptr_array_new ();
+
while (node) {
EDestination *dest;
-
+
dest = e_destination_new ();
if (e_destination_xml_decode (dest, node)) {
- dest_list = g_list_prepend (dest_list, dest);
+ g_ptr_array_add (dest_array, dest);
} else {
gtk_object_unref (GTK_OBJECT (dest));
}
-
+
node = node->next;
}
-
- N = g_list_length (dest_list);
- destv = g_new0 (EDestination *, N+1);
-
- /* We write the EDestinations into the list from back to front, to
- undo the reversal caused by using g_list_prepend instead of
- g_list_append. */
- iter = dest_list;
- while (iter != NULL) {
- destv[N-1] = E_DESTINATION (iter->data);
- iter = g_list_next (iter);
- --N;
- }
-
+
+ /* we need destv to be NULL terminated */
+ g_ptr_array_add (dest_array, NULL);
+
+ destv = (EDestination **) dest_array->pdata;
+ g_ptr_array_free (dest_array, FALSE);
+
finished:
xmlFreeDoc (destv_doc);
- g_list_free (dest_list);
-
+
return destv;
}
1:55:04 +0800'>2006-02-022-1/+59 * Only enable SVG support on 6.X and higher since it's still causing GCCmarcus2005-12-161-1/+1 * - Add a patch to fix history DoS vulnerabilityahze2005-12-092-1/+104 * - Add support for GECKO_PLIST_PRE_FILES and GECKO_PLIST_PRE_DIRS toahze2005-12-051-8/+5 * - Move .include "${.CURDIR}/../mozilla/Makefile.common" to the bottom soahze2005-12-041-1/+1 * - Disable svg support on 5.3 and lower to fix build with a gcc bug.ahze2005-12-021-2/+4 * Fix all those ports to find libnssckbi.so in the correct place to allow thosemezz2005-12-021-1/+1 * - Bump PORTREVISIONahze2005-12-011-1/+1 * - Reenable svg support, this must've sliped with all the massive changes.ahze2005-12-011-0/+1 * - Fix desktop entry, there's no FF_SUFX anymorepav2005-11-302-1/+2 * - Update WWWahze2005-11-301-1/+1 * - Update firefox to 1.5ahze2005-11-3031-1504/+105 * - Add SHA256 checksumspav2005-11-241-0/+1 * - Add support for new lib/browser_linux_pluginsahze2005-11-151-2/+2 * Bump PORTREVISION to chase the glib20 shared library update.marcus2005-11-051-1/+1 * Partially revert the previous commit. Firefox can only build with specificmarcus2005-10-102-2/+2 * * Add support of ports-installed Kerberos [1]marcus2005-10-102-3/+5 * - Fix the sed for libesd and kill the major version of librarymezz2005-09-241-7/+4 * Update to 1.0.7. Seemarcus2005-09-224-125/+20 * - Patch a security vulnerability (DoS, remote execution) in IDNpav2005-09-112-1/+105 * Add support for CJK font family names. This makes for a better browsingmarcus2005-09-022-1/+13 * - Make portlint happier.mezz2005-08-2817-327/+408 * Install IDL files into ${PREFIX}/share/idl/firefox.marcus2005-07-301-0/+11 * - Update to 1.0.6ahze2005-07-203-12/+3 * Use ${PORTVERSION} instead of duplicating its value in the MASTER_SITE_SUBDIR.marcus2005-07-141-1/+1 * Update to 1.0.5. This release addresses numerous security bugs as well asmarcus2005-07-142-4/+4 * - Update to 1.0.4ahze2005-05-122-4/+4 * - Install .desktop file in share/applications instead ofahze2005-04-271-6/+4 * - Update to 1.0.3ahze2005-04-162-5/+5 * - Remove mng support, it doesn't workahze2005-04-142-4/+2 * * Update to 1.0.2 to fix security issues (seemarcus2005-03-253-11/+14 * Bump PORTREVISION to chase the glib20 shared lib version change.marcus2005-03-121-1/+1 * Update freetype2 to 2.1.9, and patch Mozilla and friends accordingly.marcus2005-03-102-1/+343 * Fix the startup script so that arguments are passed correctly to the browsermarcus2005-03-022-123/+80 * Re-add support for specifying a profile using the -P option.marcus2005-02-281-3/+12 * Add a Mozilla Mozilla Plugable Init Script (PIS) to handle automaticallymarcus2005-02-262-1/+47 * * Update to 1.0.1 (see http://www.mozilla.org/products/firefox/releases/ formarcus2005-02-255-62/+733 * Correct a typo that prevented the Firefox Ruby script from being addedmarcus2005-01-031-2/+2 * - Update pkg-descr to better reflect firefoxahze2004-12-292-6/+12 * - Remove WITH_NEW_ICON knobahze2004-12-283-10/+24 * - Add EXTRACT_AFTER_ARGS to speed up extract a littleahze2004-12-151-0/+7 * * Fix build with upcoming X.Org 6.8.1 [1]marcus2004-12-153-1/+15 * Add Encoding type to desktop file to validate via desktop-file-validateahze2004-12-131-0/+1 * Bump PORTREVISION for plist changesahze2004-12-111-1/+1 * - Fix plist in firefox [1]ahze2004-12-111-0/+3 * Fix plist by fixing the way EXTRA_SCRIPTS (bin/firefox.rb) is added to plist.ahze2004-12-101-1/+1 * Be sure to create the browser_plugins during package install as well. Somemarcus2004-12-042-0/+5 * Use -Bsymbolic when linking nss to avoid symbol conflicts with librariesmarcus2004-11-222-6/+20 * Fix a patch.mezz2004-11-211-1/+1 * Instead of using Xvfb, and evil black magic to create the extensionsmarcus2004-11-192-6/+2 * Fix pkg-config files by re-adding REINPLACE_CMD lineahze2004-11-151-1/+2 * Change the Firefox installation directory to be more manageable. Now,ahze2004-11-133-81/+108 * * Update to 1.0marcus2004-11-104-10/+26 * Bump PORTREVISIONS for all ports that depend on atk or pango to ease in themarcus2004-11-081-0/+1 * update to 1.0.r2ahze2004-11-062-5/+5 * Update to 1.0.r (aka 1.0 Release Candidate 1). So far, the release notes havemarcus2004-10-294-24/+8 * Essentially a NOP commit. The xpcom reflect patches for amd64 supportpeter2004-10-242-389/+1 * * Remove some patches that are no longer neededmarcus2004-10-185-39/+13 * Check PERL_LEVEL and not OSVERSION when deciding if we need to use the extramarcus2004-10-141-1/+1 * Bump PORTREVISION for the last commit since it re-enables remote executionmarcus2004-10-141-1/+1 * Add a patch that was forgotten in the 1.0.1.p update.marcus2004-10-141-0/+10 * Fix build with Perl 5.00503.marcus2004-10-142-0/+14 * * Update to 1.0.1.p (aka 0.10.1, aka 1.0PR)marcus2004-10-1210-161/+23 * Patch the various recently reported security vulnerabilities in Mozilla.marcus2004-09-284-0/+101 * Update to 0.9.3 to fix a few security issues:marcus2004-08-063-4/+29 * Fix global extension and theme installation by making sure the path to themarcus2004-07-282-0/+18 * Fix DEBUG builds by checking for all error states from pthread_mutex_trylock().marcus2004-07-271-0/+11 * Update to 0.9.1.marcus2004-06-302-4/+3 * * Add optional support for gnome-vfs support (e.g. smb:// and sftp:// URLs) [1]marcus2004-06-254-3/+51 * Add a post-rendered Extensions.rdf so that the default theme and extensionmarcus2004-06-203-5/+45 * Add a patch to run g_thread_init() as soon as Firefox starts. This is saidmarcus2004-06-192-0/+20 * * Try a little harder to get firefox to work without first running as rootmarcus2004-06-193-25/+24 * The warning about running as root first is no longer needed since themarcus2004-06-171-14/+0 * Fix the link to firefox-config.marcus2004-06-171-2/+3 * Fix a typo in the pkg-install script, and add a hack so that firefox does notmarcus2004-06-162-2/+6