/pidgin/main: 02346b6472b3: Simplify checks for empty strings
Michael McConville
mmcconville at mykolab.com
Thu Jan 14 00:10:25 EST 2016
Changeset: 02346b6472b36a5a7d303657555712ece0e2f7d9
Author: Michael McConville <mmcconville at mykolab.com>
Date: 2016-01-14 00:09 -0500
Branch: default
URL: https://hg.pidgin.im/pidgin/main/rev/02346b6472b3
Description:
Simplify checks for empty strings
strlen walks though the entire string, and compilers are bad at
optimizing away libc functions calls. Therefore, it's easiest to just
dereference a char* when checking whether it represents an empty string.
diffstat:
finch/gntsound.c | 2 +-
libpurple/protocols/gg/blist.c | 2 +-
libpurple/protocols/gg/roster.c | 2 +-
libpurple/protocols/irc/irc.c | 2 +-
libpurple/protocols/oscar/family_bart.c | 2 +-
libpurple/protocols/oscar/family_icbm.c | 6 +++---
libpurple/protocols/silc/util.c | 6 +++---
libpurple/protocols/yahoo/yahoo_aliases.c | 2 +-
libpurple/protocols/zephyr/zephyr.c | 2 +-
pidgin/gtksound.c | 2 +-
10 files changed, 14 insertions(+), 14 deletions(-)
diffs (144 lines):
diff --git a/finch/gntsound.c b/finch/gntsound.c
--- a/finch/gntsound.c
+++ b/finch/gntsound.c
@@ -597,7 +597,7 @@ finch_sound_play_event(PurpleSoundEventI
/* check NULL for sounds that don't have an option, ie buddy pounce */
if (purple_prefs_get_bool(enable_pref)) {
char *filename = g_strdup(purple_prefs_get_path(file_pref));
- if (!filename || !strlen(filename)) {
+ if (!filename || *filename == '\0') {
g_free(filename);
filename = g_build_filename(PURPLE_DATADIR,
"sounds", "purple", sounds[event].def, NULL);
diff --git a/libpurple/protocols/gg/blist.c b/libpurple/protocols/gg/blist.c
--- a/libpurple/protocols/gg/blist.c
+++ b/libpurple/protocols/gg/blist.c
@@ -137,7 +137,7 @@ void ggp_buddylist_load(PurpleConnection
}
buddy = purple_buddy_new(purple_connection_get_account(gc),
- name, strlen(show) ? show : NULL);
+ name, *show == '\0' ? NULL : show);
if (!(group = purple_blist_find_group(g))) {
group = purple_group_new(g);
diff --git a/libpurple/protocols/gg/roster.c b/libpurple/protocols/gg/roster.c
--- a/libpurple/protocols/gg/roster.c
+++ b/libpurple/protocols/gg/roster.c
@@ -497,7 +497,7 @@ static gboolean ggp_roster_reply_list_re
g_hash_table_insert(content->contact_nodes, GINT_TO_POINTER(uin), node);
/* check, if alias is set */
- if (strlen(alias) == 0 ||
+ if (*alias == '\0' ||
strcmp(alias, ggp_uin_to_str(uin)) == 0)
{
g_free(alias);
diff --git a/libpurple/protocols/irc/irc.c b/libpurple/protocols/irc/irc.c
--- a/libpurple/protocols/irc/irc.c
+++ b/libpurple/protocols/irc/irc.c
@@ -435,7 +435,7 @@ static gboolean do_login(PurpleConnectio
}
buf = irc_format(irc, "vvvv:", "USER", tmp ? tmp : identname, "*", server,
- strlen(realname) ? realname : IRC_DEFAULT_ALIAS);
+ *realname == '\0' ? IRC_DEFAULT_ALIAS : realname);
g_free(tmp);
g_free(server);
if (irc_send(irc, buf) < 0) {
diff --git a/libpurple/protocols/oscar/family_bart.c b/libpurple/protocols/oscar/family_bart.c
--- a/libpurple/protocols/oscar/family_bart.c
+++ b/libpurple/protocols/oscar/family_bart.c
@@ -100,7 +100,7 @@ aim_bart_request(OscarData *od, const ch
ByteStream bs;
aim_snacid_t snacid;
- if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_BART)) || !bn || !strlen(bn) || !iconcsum || !iconcsumlen)
+ if (!od || !(conn = flap_connection_findbygroup(od, SNAC_FAMILY_BART)) || !bn || *bn == '\0' || !iconcsum || !iconcsumlen)
return -EINVAL;
byte_stream_new(&bs, 1+strlen(bn) + 4 + 1+iconcsumlen);
diff --git a/libpurple/protocols/oscar/family_icbm.c b/libpurple/protocols/oscar/family_icbm.c
--- a/libpurple/protocols/oscar/family_icbm.c
+++ b/libpurple/protocols/oscar/family_icbm.c
@@ -1352,11 +1352,11 @@ static int incomingim_ch2(OscarData *od,
if (aim_tlv_gettlv(list2, 0x0010, 1))
args.use_proxy = TRUE;
- if (strlen(proxyip))
+ if (*proxyip != '\0')
args.proxyip = (char *)proxyip;
- if (strlen(clientip))
+ if (*clientip != '\0')
args.clientip = (char *)clientip;
- if (strlen(verifiedip))
+ if (*verifiedip != '\0')
args.verifiedip = (char *)verifiedip;
/*
diff --git a/libpurple/protocols/silc/util.c b/libpurple/protocols/silc/util.c
--- a/libpurple/protocols/silc/util.c
+++ b/libpurple/protocols/silc/util.c
@@ -500,7 +500,7 @@ silcpurple_parse_attrs(SilcDList attrs,
if (mood & SILC_ATTRIBUTE_MOOD_ANXIOUS)
g_string_append_printf(s, "[%s] ", _("Anxious"));
}
- if (strlen(s->str)) {
+ if (*s->str != '\0') {
*moodstr = g_string_free(s, FALSE);
g_strchomp(*moodstr);
} else
@@ -529,7 +529,7 @@ silcpurple_parse_attrs(SilcDList attrs,
if (contact & SILC_ATTRIBUTE_CONTACT_VIDEO)
g_string_append_printf(s, "[%s] ", _("Video Conferencing"));
}
- if (strlen(s->str)) {
+ if (*s->str != '\0') {
*contactstr = g_string_free(s, FALSE);
g_strchomp(*contactstr);
} else
@@ -558,7 +558,7 @@ silcpurple_parse_attrs(SilcDList attrs,
device.model ? device.model : "",
device.language ? device.language : "");
}
- if (strlen(s->str))
+ if (*s->str != '\0')
*devicestr = g_string_free(s, FALSE);
else
g_string_free(s, TRUE);
diff --git a/libpurple/protocols/yahoo/yahoo_aliases.c b/libpurple/protocols/yahoo/yahoo_aliases.c
--- a/libpurple/protocols/yahoo/yahoo_aliases.c
+++ b/libpurple/protocols/yahoo/yahoo_aliases.c
@@ -133,7 +133,7 @@ yahoo_fetch_aliases_cb(PurpleHttpConnect
if (nick_name != NULL)
alias = nick_name; /* If we have a nickname from Yahoo, let's use it */
- else if (strlen(full_name) != 0)
+ else if (*full_name != '\0')
alias = full_name; /* If no Yahoo nickname, we can use the full_name created above */
/* Find the local buddy that matches */
diff --git a/libpurple/protocols/zephyr/zephyr.c b/libpurple/protocols/zephyr/zephyr.c
--- a/libpurple/protocols/zephyr/zephyr.c
+++ b/libpurple/protocols/zephyr/zephyr.c
@@ -2456,7 +2456,7 @@ static void zephyr_join_chat(PurpleConne
if (!g_ascii_strcasecmp(classname,"%canon%"))
classname = g_strdup(zephyr->ourhostcanon);
- if (!instname || !strlen(instname))
+ if (!instname || *instname == '\0')
instname = "*";
if (!g_ascii_strcasecmp(instname,"%host%"))
diff --git a/pidgin/gtksound.c b/pidgin/gtksound.c
--- a/pidgin/gtksound.c
+++ b/pidgin/gtksound.c
@@ -626,7 +626,7 @@ pidgin_sound_play_event(PurpleSoundEvent
}
}
- if (!filename || !strlen(filename)) { /* Use Default sounds */
+ if (!filename || *filename == '\0') { /* Use Default sounds */
g_free(filename);
filename = g_build_filename(PURPLE_DATADIR,
More information about the Commits
mailing list