Patch : clean-ups
- From: Emmanuel <e allaud wanadoo fr>
- To: balsa-list gnome org
- Subject: Patch : clean-ups
- Date: Sat, 13 Oct 2001 13:39:52 +0200
Hi all,
here is a small patch with only minor clean-ups, mainly
strlen(somestring)==0 replaced by somestring[0]=='\0'.
I find a lot of places where we do things like that :
if (i>strlen(somestring)) i=strlen(somestring);
or things like
for (i=1;i<strlen(sometring);i++) { ... }
where somestring is constant throughout the loop, so I don't think this is
optimized by gcc (or it is really smart).
Is is worth the pain to make a patch correcting these sorts of things?
Bye
Manu
diff -u balsa-1.2.0/libbalsa/address-entry.c test/balsa-1.2.0/libbalsa/address-entry.c
--- balsa-1.2.0/libbalsa/address-entry.c Fri Aug 24 18:27:00 2001
+++ test/balsa-1.2.0/libbalsa/address-entry.c Sat Oct 13 13:19:26 2001
@@ -492,10 +492,11 @@
static gboolean
libbalsa_is_an_email(gchar *str) {
gboolean found;
- unsigned i;
+ unsigned i,len;
found = FALSE;
- for (i = 0; i < strlen(str); i++)
+ len=strlen(str);
+ for (i = 0; i < len; i++)
if ((str[i] == (gchar) '@') ||
(str[i] == (gchar) '%') ||
(str[i] == (gchar) '!')) found = TRUE;
@@ -778,7 +779,7 @@
if (input->active != input->list)
addy->cursor = addy->cursor - 1; /* Compensate for the ',' */
if (addy->cursor < 0) addy->cursor = 0;
- if (addy->cursor > strlen(addy->user)) addy->cursor = strlen(addy->user);
+ else if (addy->cursor > strlen(addy->user)) addy->cursor = strlen(addy->user);
return input;
}
@@ -1613,7 +1614,7 @@
g_free(left);
addy->user = str;
addy->cursor--;
- if (strlen(str) == 0)
+ if (str[0] == '\0')
libbalsa_force_no_match(addy);
else if (address_entry->find_match)
(*address_entry->find_match) (addy, TRUE);
@@ -1770,14 +1771,14 @@
* domain to add to e-mail addresses.
*/
if (address_entry->domain == NULL) return;
- if (strlen(address_entry->domain) == 0) return;
+ if (address_entry->domain[0] == '\0') return;
/*
* There is a default domain to add. Do we need to add it?
*/
addy = address_entry->input->active->data;
if (libbalsa_is_an_email(addy->user)) return;
- if (strlen(addy->user) == 0) return;
+ if (addy->user[0] == '\0') return;
/*
* Okay, add it.
@@ -2013,7 +2014,7 @@
* And we add the default domain to the original entry.
*/
if (address_entry->domain == NULL) return;
- if (strlen(address_entry->domain) == 0) return;
+ if (address_entry->domain[0] == '\0') return;
if (libbalsa_is_an_email(addy->user)) return;
str = g_strconcat(addy->user, "@", address_entry->domain, NULL);
g_free(addy->user);
diff -u balsa-1.2.0/src/address-book.c test/balsa-1.2.0/src/address-book.c
--- balsa-1.2.0/src/address-book.c Mon Aug 13 15:17:29 2001
+++ test/balsa-1.2.0/src/address-book.c Sat Oct 13 13:21:30 2001
@@ -653,7 +653,7 @@
entry_text = gtk_entry_get_text(GTK_ENTRY(group_entry));
- if (strlen(entry_text) == 0)
+ if (entry_text[0] == '\0')
return;
gtk_clist_unselect_all(GTK_CLIST(ab->address_clist));
diff -u balsa-1.2.0/src/expand-alias.c test/balsa-1.2.0/src/expand-alias.c
--- balsa-1.2.0/src/expand-alias.c Thu Sep 6 10:59:38 2001
+++ test/balsa-1.2.0/src/expand-alias.c Sat Oct 13 13:22:06 2001
@@ -100,7 +100,7 @@
g_free(addy->match);
addy->match = NULL;
- if(strlen(input) == 0) {
+ if(input[0] == '\0') {
addy->match = g_strdup("");
return;
}
diff -u balsa-1.2.0/src/mailbox-conf.c test/balsa-1.2.0/src/mailbox-conf.c
--- balsa-1.2.0/src/mailbox-conf.c Thu Aug 23 23:24:37 2001
+++ test/balsa-1.2.0/src/mailbox-conf.c Sat Oct 13 13:23:50 2001
@@ -521,7 +521,7 @@
if (!(*name =
g_strdup(gtk_entry_get_text(GTK_ENTRY(mcw->mailbox_name))))
- || strlen(g_strstrip(*name)) == 0) {
+ || g_strstrip(*name)[0] == '\0') {
if (*name)
g_free(*name);
diff -u balsa-1.2.0/src/sendmsg-window.c test/balsa-1.2.0/src/sendmsg-window.c
--- balsa-1.2.0/src/sendmsg-window.c Tue Sep 18 16:19:28 2001
+++ test/balsa-1.2.0/src/sendmsg-window.c Sat Oct 13 13:28:04 2001
@@ -636,8 +636,8 @@
/* change entries to reflect new identity */
- if (strlen(ident->address->full_name) &&
- strlen(ident->address->address_list->data)) {
+ if (ident->address->full_name[0]!='\0' &&
+ ((gchar *)ident->address->address_list->data)[0]!='\0') {
tmpstr = g_strdup_printf("%s <%s>", ident->address->full_name,
(gchar*)ident->address->address_list->data);
gtk_entry_set_text(GTK_ENTRY(msg->from[1]), tmpstr);
@@ -921,7 +921,7 @@
guint info, guint32 time, GnomeIconList * iconlist)
{
- if (strlen(gtk_entry_get_text(GTK_ENTRY(widget))) == 0) {
+ if (gtk_entry_get_text(GTK_ENTRY(widget))[0] == '\0') {
gtk_entry_set_text(GTK_ENTRY(widget), selection_data->data);
} else {
gtk_entry_append_text(GTK_ENTRY(widget), ",");
@@ -2021,7 +2021,7 @@
(GTK_ENTRY(bsmsg->bcc[1])));
if ((tmp = gtk_entry_get_text(GTK_ENTRY(bsmsg->reply_to[1]))) != NULL
- && strlen(tmp) > 0)
+ && tmp[0]!='\0')
message->reply_to = libbalsa_address_new_from_string(tmp);
if (balsa_app.req_dispnotify)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]