[MPlayer-cvslog] r33066 - in trunk/gui: mplayer/gui_common.c skin/cut.c skin/skin.c

ib subversion at mplayerhq.hu
Thu Mar 10 15:20:36 CET 2011


Author: ib
Date: Thu Mar 10 15:20:36 2011
New Revision: 33066

Log:
Replace some awkward and unnecessary usages of strlen().

1. A string length of zero or greater than zero can be determined by checking
   the first byte.

2. Leave it to strdup() to determine the length and to do allocation for a
   string that is to be copied.

3. If neither the string length nor the index variable is altered in a loop,
   string[index] (!= 0) is the condition to go with.

Modified:
   trunk/gui/mplayer/gui_common.c
   trunk/gui/skin/cut.c
   trunk/gui/skin/skin.c

Modified: trunk/gui/mplayer/gui_common.c
==============================================================================
--- trunk/gui/mplayer/gui_common.c	Thu Mar 10 14:22:11 2011	(r33065)
+++ trunk/gui/mplayer/gui_common.c	Thu Mar 10 15:20:36 2011	(r33066)
@@ -91,7 +91,7 @@ static void TranslateFilename(int c, cha
     }
 
     if (c) {
-        for (i = 0; i < (int)strlen(tmp); i++) {
+        for (i = 0; tmp[i]; i++) {
             int t = 0;
 
             if (c == 1)

Modified: trunk/gui/skin/cut.c
==============================================================================
--- trunk/gui/skin/cut.c	Thu Mar 10 14:22:11 2011	(r33065)
+++ trunk/gui/skin/cut.c	Thu Mar 10 15:20:36 2011	(r33066)
@@ -26,7 +26,7 @@ void cutItemString(char *in, char *out, 
     int n;
     unsigned int i, c;
 
-    for (c = 0, n = 0, i = 0; i < strlen(in); i++) {
+    for (c = 0, n = 0, i = 0; in[i]; i++) {
         if (in[i] == sep)
             n++;
         if (n >= num && in[i] != sep && c + 1 < maxout)

Modified: trunk/gui/skin/skin.c
==============================================================================
--- trunk/gui/skin/skin.c	Thu Mar 10 14:22:11 2011	(r33065)
+++ trunk/gui/skin/skin.c	Thu Mar 10 15:20:36 2011	(r33066)
@@ -179,7 +179,7 @@ static int cmd_end(char *in)
 
     mp_dbg(MSGT_GPLAYER, MSGL_DBG2, "[skin]  %send (%s)\n", space, name);
 
-    if (strlen(window_name)) {
+    if (window_name[0]) {
         window_name[0] = 0;
         currSection    = NULL;
         currSubItem    = NULL;
@@ -711,14 +711,13 @@ static int cmd_slabel(char *in)
     item->y      = y;
     item->width  = -1;
     item->height = -1;
+    item->label  = strdup(tmp);
 
-    if ((item->label = malloc(strlen(tmp) + 1)) == NULL) {
+    if (!item->label) {
         ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory);
         return 1;
     }
 
-    strcpy(item->label, tmp);
-
     return 0;
 }
 
@@ -766,14 +765,13 @@ static int cmd_dlabel(char *in)
     item->y      = y;
     item->width  = sx;
     item->height = -1;
+    item->label  = strdup(tmp);
 
-    if ((item->label = malloc(strlen(tmp) + 1)) == NULL) {
+    if (!item->label) {
         ERRORMESSAGE(MSGTR_SKIN_FONT_NotEnoughtMemory);
         return 1;
     }
 
-    strcpy(item->label, tmp);
-
     return 0;
 }
 
@@ -829,10 +827,10 @@ char *strswap(char *in, char what, char 
 {
     int i;
 
-    if (strlen(in) == 0)
+    if (!*in)
         return NULL;
 
-    for (i = 0; i < (int)strlen(in); i++)
+    for (i = 0; in[i]; i++)
         if (in[i] == what)
             in[i] = whereof;
 
@@ -843,7 +841,7 @@ char *trim(char *in)
 {
     int c = 0, id = 0, i;
 
-    if (strlen(in) == 0)
+    if (!*in)
         return NULL;
 
     while (c != (int)strlen(in)) {


More information about the MPlayer-cvslog mailing list