* revert to the in-place 'modest_text_utils_get_display_address',
authorDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 16 Oct 2007 08:50:40 +0000 (08:50 +0000)
committerDirk-Jan C. Binnema <dirk-jan.binnema@nokia.com>
Tue, 16 Oct 2007 08:50:40 +0000 (08:50 +0000)
  and make it a bit faster.

pmo-trunk-r3507

src/maemo/modest-platform.c
src/modest-text-utils.c
src/modest-text-utils.h
src/widgets/modest-header-view-render.c

index a07ce84..d848149 100644 (file)
@@ -1242,7 +1242,10 @@ modest_platform_on_new_headers_received (TnyList *header_list)
                gint notif_id;
        
                display_date = modest_text_utils_get_display_date (tny_header_get_date_received (header));
-               display_address = modest_text_utils_get_display_address (tny_header_get_from (header));
+
+               display_address = g_strdup(tny_header_get_from (header));
+               modest_text_utils_get_display_address (display_address); /* string is changed in-place */
+               
                summary = g_strdup_printf ("%s - %s", display_date, display_address);
                notification = hildon_notification_new (summary,
                                                        tny_header_get_subject (header),
index 9bf3de2..6b3709c 100644 (file)
@@ -953,36 +953,39 @@ hyperlinkify_plain_text (GString *txt)
 }
 
 
-gchar*
-modest_text_utils_get_display_address (const gchar *address)
+/* for optimization reasons, we change the string in-place */
+void
+modest_text_utils_get_display_address (gchar *address)
 {
-       gchar *display;
-       gchar **tokens;
-       gint i = 0;
+       int i;
        
        if (!address)
-               return NULL;
-
-       g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
+               return;
        
-       tokens = g_strsplit_set ((const gchar*) address, "<>()", 3);
-
-       /* Note that if any of the delimiters is the first character
-          then g_strsplit_set will return "" as the first string */
-       while (tokens[i] != NULL) {
-               if (strlen ((char *) (tokens[i])) != 0)
-                       break;
-               i++;
+       /* should not be needed, and otherwise, we probably won't screw up the address
+        * more than it already is :) 
+        * g_return_val_if_fail (g_utf8_validate (address, -1, NULL), NULL);
+        * */
+       
+       /* remove leading whitespace */
+       if (address[0] == ' ')
+               g_strchug (address);
+               
+       for (i = 0; address[i]; ++i) {
+               if (address[i] == '<') {
+                       if (G_UNLIKELY(i == 0))
+                               return; /* there's nothing else, leave it */
+                       else {
+                               address[i] = '\0'; /* terminate the string here */
+                               return;
+                       }
+               }
        }
+}
+
 
-       display = g_strdup (tokens [i]);
-       g_strchug (display);
 
-       /* Free the other tokens */
-       g_strfreev (tokens);
 
-       return display;
-}
 
 gchar *
 modest_text_utils_get_email_address (const gchar *full_address)
@@ -1142,6 +1145,8 @@ modest_text_utils_validate_domain_name (const gchar *domain)
        regex_t rx;
        const gchar* domain_regex = "^[a-z0-9]([.]?[a-z0-9-])*[a-z0-9]$";
 
+       memset (&rx, 0, sizeof(regex_t)); /* coverity wants this... */
+       
        if (!domain)
                return FALSE;
        
index c51499b..5945c34 100644 (file)
@@ -200,14 +200,14 @@ size_t modest_text_utils_strftime(char *s, size_t max, const char  *fmt, time_t
  * @address: original address (UTF8 string)
  *
  * make a 'display address' from an address:
- * "Foo Bar <foo@bar.cx> (Bla)" --> "Foo Bar"
- * ie. removes "<...>" and "(...)" parts
- * the change is in-place; removes leading/trailing whitespace
+ * "Foo Bar <foo@bar.cx>" --> "Foo Bar"
+ * ie. removes "<...>" parts
+ * the change is in-place; removes leading whitespace
  * 
- * Returns: a new allocated string with the display address. NULL in
- * case of error or if address == NULL
+ * NOTE: for optimization reasons, this function changes @address
+ * in-place
  */
-gchar* modest_text_utils_get_display_address (const gchar *address);
+void modest_text_utils_get_display_address (gchar *address);
 
 /**
  * modest_text_utils_get_email_address:
@@ -381,7 +381,18 @@ typedef enum {
        USER_NAME_FORBIDDEN_NAMES,
 } ModestTextUtilsForbiddenCharType;
 
+
+/**
+ * modest_text_utils_is_forbidden_char:
+ * @character: some character
+ * @type: the type of forbidden char (see #ModestTextUtilsForbiddenCharType)
+ * 
+ * check whether the given character is 'forbidden'
+ *
+ * Returns: TRUE if it's forbidden, FALSE otherwise
+ */
 gboolean     modest_text_utils_is_forbidden_char (const gchar character,
                                                  ModestTextUtilsForbiddenCharType type);
 
+
 #endif /* __MODEST_TEXT_UTILS_H__ */
index 2f8b599..1625a94 100644 (file)
@@ -264,7 +264,7 @@ _modest_header_view_sender_receiver_cell_data  (GtkTreeViewColumn *column,
                                                gboolean is_sender)
 {
        TnyHeaderFlags flags;
-       gchar *address, *display_address;
+       gchar *address;
        gint sender_receiver_col;
 
        if (is_sender)
@@ -277,13 +277,13 @@ _modest_header_view_sender_receiver_cell_data  (GtkTreeViewColumn *column,
                            TNY_GTK_HEADER_LIST_MODEL_FLAGS_COLUMN, &flags,
                            -1);
        
-       display_address = modest_text_utils_get_display_address (address);
+       modest_text_utils_get_display_address (address); /* string is changed in-place */
        g_object_set (G_OBJECT(renderer),
                      "text",
-                     display_address,
+                     address,
                      NULL);
-       g_free (display_address);
        g_free (address);
+
        set_common_flags (renderer, flags);
 }
 /*
@@ -305,7 +305,7 @@ _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCe
        
        TnyHeaderFlags flags = 0;
        TnyHeaderFlags prior_flags = 0;
-       gchar *address = NULL, *display_address;
+       gchar *address = NULL;
        gchar *subject = NULL;
        gchar *header = NULL;
        time_t date = 0;
@@ -376,12 +376,10 @@ _modest_header_view_compact_header_cell_data  (GtkTreeViewColumn *column,  GtkCe
 
        /* FIXME: we hardcode the color to #666666; instead we should use SecondaryTextColour from the
         * theme (gtkrc file) */
-       display_address = modest_text_utils_get_display_address (address);
+       modest_text_utils_get_display_address (address); /* changed in-place */
        header = g_markup_printf_escaped ("<span size='small' foreground='#666666'>%s</span>",
-                                         display_address);
-       g_free (display_address);
+                                         address);
        g_free (address);
-       address = display_address = NULL;
        g_object_set (G_OBJECT (recipient_cell),
                      "markup", header,
                      NULL);