On 11/4/11 11:16 AM, Måns Rullgård wrote:
Luca Barbato<[email protected]>  writes:

On 11/4/11 9:45 AM, Kostya Shishkov wrote:
On Fri, Nov 04, 2011 at 04:42:11PM +0000, Måns Rullgård wrote:
Luca Barbato<[email protected]>   writes:

On 11/4/11 9:28 AM, Måns Rullgård wrote:
Write it in a non-ugly way of course.

Let me expand:

- the strcasecmp/strncasecmp itself isn't much different than the
usual libc implementation, the toupper can enjoy a better
implementation (to be noted that in all libc I had a look into strcase
uses tolower).

Yes, that macro is what I was talking about.

What about

#define TOUPPER(c) \
     if (c>= 'a'&&   c<= 'z') \
         c ^= 0x20;

Looks nicer.

I'd make it a bit more function-like or even an inline function.


Do we have other uses for it (seems we are using toupper somewhere as well?

lu
diff --git a/libavutil/avstring.c b/libavutil/avstring.c
index 0f01eab..1e2f0e8 100644
--- a/libavutil/avstring.c
+++ b/libavutil/avstring.c
@@ -134,16 +134,26 @@ char *av_get_token(const char **buf, const char *term)
     return ret;
 }
 
-#define TOUPPER(c) do { if (c >= 'a' && c <= 'z') c -= 'a' - 'A'; } while (0)
+inline int av_toupper(int c)
+{
+    if (c >= 'a' && c <= 'z')
+        c ^= 0x20;
+    return c;
+}
+
+inline int av_tolower(int c)
+{
+    if (c >= 'A' && c <= 'Z')
+        c ^= 0x20;
+    return c;
+}
 
 int av_strcasecmp(const char *a, const char *b)
 {
     uint8_t c1, c2;
     do {
-        c1 = *a++;
-        c2 = *b++;
-        TOUPPER(c1);
-        TOUPPER(c2);
+        c1 = av_tolower(*a++);
+        c2 = av_tolower(*b++);
     } while (c1 && c1 == c2);
     return c1 - c2;
 }
@@ -153,10 +163,8 @@ int av_strncasecmp(const char *a, const char *b, size_t n)
     const char *end = a + n;
     uint8_t c1, c2;
     do {
-        c1 = *a++;
-        c2 = *b++;
-        TOUPPER(c1);
-        TOUPPER(c2);
+        c1 = av_tolower(*a++);
+        c2 = av_tolower(*b++);
     } while (a < end && c1 && c1 == c2);
     return c1 - c2;
 }
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to