ws2_32: Restructure and simplify debugstr_wsaioctl a bit.

Gerald Pfeifer gerald at pfeifer.com
Sat Jan 8 09:47:59 CST 2011


On Tue, 28 Sep 2010, Juan Lang wrote:
>> This mimicks what we already do a few lines above for buf_type.
> It's also unneeded:
> 
>     switch(ioctl & 0x18000000)
> 
> There are only 4 possible combinations of ioctl & 0x18000000.  Three
> are covered in this switch statement, and the fourth is eliminated due
> to the outer switch statement.  You'd be adding dead code.

You're right, good catch.  That said, this code is really a bit
tricky and looks more complicated than it needs be.

How about the patch below which avoids the nested switch statement,
allows the compiler to realize what's going on, and makes the code
smaller, too.  (Not sure why the difference appears that large, but
socket.o goes down from 493528 bytes to 492476 on my tester.)
 
Gerald

---
 dlls/ws2_32/socket.c |   69 ++++++++++++++++++++++---------------------------
 1 files changed, 31 insertions(+), 38 deletions(-)

diff --git a/dlls/ws2_32/socket.c b/dlls/ws2_32/socket.c
index 3d85bad..f7607c5 100644
--- a/dlls/ws2_32/socket.c
+++ b/dlls/ws2_32/socket.c
@@ -2967,14 +2967,24 @@ char* WINAPI WS_inet_ntoa(struct WS_in_addr in)
 
 static const char *debugstr_wsaioctl(DWORD ioctl)
 {
+    const char *buf_type, *family;
+
     switch(ioctl & 0x18000000)
     {
-    case WS_IOC_UNIX:
+    case WS_IOC_WS2:
+        family = "IOC_WS2";
+        break;
+    case WS_IOC_PROTOCOL:
+        family = "IOC_PROTOCOL";
+        break;
+    case WS_IOC_VENDOR:
+        family = "IOC_VENDOR";
+        break;
+    default: /* WS_IOC_UNIX */
     {
         BYTE size = (ioctl >> 16) & WS_IOCPARM_MASK;
         char x = (ioctl & 0xff00) >> 8;
         BYTE y = ioctl & 0xff;
-        const char *buf_type;
         char args[14];
 
         switch (ioctl & (WS_IOC_VOID|WS_IOC_INOUT))
@@ -2998,47 +3008,30 @@ static const char *debugstr_wsaioctl(DWORD ioctl)
         }
         return wine_dbg_sprintf("%s(%s)", buf_type, args);
     }
-    default:
-    {
-        USHORT code = ioctl & 0xffff;
-        const char *family, *buf_type;
+    }
 
-        /* This switch looks redundant, but isn't:  the case WS_IOC_UNIX
-         * is handled differently than all others.
-         */
-        switch(ioctl & 0x18000000)
-        {
-        case WS_IOC_WS2:
-            family = "IOC_WS2";
+    /* We are different from WS_IOC_UNIX. */
+    switch (ioctl & (WS_IOC_VOID|WS_IOC_INOUT))
+    {
+        case WS_IOC_VOID:
+            buf_type = "_WSAIO";
             break;
-        case WS_IOC_PROTOCOL:
-            family = "IOC_PROTOCOL";
+        case WS_IOC_INOUT:
+            buf_type = "_WSAIORW";
             break;
-        case WS_IOC_VENDOR:
-            family = "IOC_VENDOR";
+        case WS_IOC_IN:
+            buf_type = "_WSAIOW";
+            break;
+        case WS_IOC_OUT:
+            buf_type = "_WSAIOR";
+            break;
+        default:
+            buf_type = "?";
             break;
-        }
-        switch (ioctl & (WS_IOC_VOID|WS_IOC_INOUT))
-        {
-            case WS_IOC_VOID:
-                buf_type = "_WSAIO";
-                break;
-            case WS_IOC_INOUT:
-                buf_type = "_WSAIORW";
-                break;
-            case WS_IOC_IN:
-                buf_type = "_WSAIOW";
-                break;
-            case WS_IOC_OUT:
-                buf_type = "_WSAIOR";
-                break;
-            default:
-                buf_type = "?";
-                break;
-        }
-        return wine_dbg_sprintf("%s(%s, %d)", buf_type, family, code);
-    }
     }
+
+    return wine_dbg_sprintf("%s(%s, %d)", buf_type, family,
+                            (USHORT)(ioctl & 0xffff));
 }
 
 /**********************************************************************
-- 
1.7.2.2



More information about the wine-patches mailing list