changeset 34177:fadc00cc31d3

Optimize TranslateFilename(). Replace for loop with index by while loop with pointer. Unite the if conditions.
author ib
date Wed, 26 Oct 2011 15:52:06 +0000
parents d52b0ad317d5
children 3c0cf739f1e1
files gui/util/string.c
diffstat 1 files changed, 10 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/gui/util/string.c	Wed Oct 26 15:40:47 2011 +0000
+++ b/gui/util/string.c	Wed Oct 26 15:52:06 2011 +0000
@@ -249,7 +249,6 @@
  */
 char *TranslateFilename(int how, char *fname, size_t maxlen)
 {
-    int i;
     char *p;
     size_t len;
 
@@ -305,18 +304,18 @@
     }
 
     if (how) {
-        for (i = 0; fname[i]; i++) {
-            int t = 0;
+        p = fname;
+
+        while (*p) {
+            char t = 0;
 
-            if (how == 1)
-                if (fname[i] >= 'A' && fname[i] <= 'Z')
-                    t = 32;
+            if (how == 1 && *p >= 'A' && *p <= 'Z')
+                t = 32;
+            if (how == 2 && *p >= 'a' && *p <= 'z')
+                t = -32;
 
-            if (how == 2)
-                if (fname[i] >= 'a' && fname[i] <= 'z')
-                    t = -32;
-
-            fname[i] = (char)(fname[i] + t);
+            *p = *p + t;
+            p++;
         }
     }