richedit: Implement ME_DITypesEqual using a switch statment.

Dylan Smith dylan.ah.smith at gmail.com
Mon Aug 10 09:53:21 CDT 2009


Previously a series of if statements were used, but a switch statement
should be optimized better by the compiler.
---
 dlls/riched20/list.c |   34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)
-------------- next part --------------
diff --git a/dlls/riched20/list.c b/dlls/riched20/list.c
index d3d9463..06f1121 100644
--- a/dlls/riched20/list.c
+++ b/dlls/riched20/list.c
@@ -44,23 +44,23 @@ void ME_Remove(ME_DisplayItem *diWhere)
 
 static BOOL ME_DITypesEqual(ME_DIType type, ME_DIType nTypeOrClass)
 {
-  if (type==nTypeOrClass)
-    return TRUE;
-  if (nTypeOrClass==diRunOrParagraph && (type==diRun || type==diParagraph))
-    return TRUE;
-  if (nTypeOrClass==diRunOrStartRow && (type==diRun || type==diStartRow))
-    return TRUE;
-  if (nTypeOrClass==diParagraphOrEnd && (type==diTextEnd || type==diParagraph))
-    return TRUE;
-  if (nTypeOrClass==diStartRowOrParagraph && (type==diStartRow || type==diParagraph))
-    return TRUE;
-  if (nTypeOrClass==diStartRowOrParagraphOrEnd
-    && (type==diStartRow || type==diParagraph || type==diTextEnd))
-    return TRUE;
-  if (nTypeOrClass==diRunOrParagraphOrEnd
-    && (type==diRun || type==diParagraph || type==diTextEnd))
-    return TRUE;
-  return FALSE;
+  switch (nTypeOrClass)
+  {
+    case diRunOrParagraph:
+      return type == diRun || type == diParagraph;
+    case diRunOrStartRow:
+      return type == diRun || type == diStartRow;
+    case diParagraphOrEnd:
+      return type == diTextEnd || type == diParagraph;
+    case diStartRowOrParagraph:
+      return type == diStartRow || type == diParagraph;
+    case diStartRowOrParagraphOrEnd:
+      return type == diStartRow || type == diParagraph || type == diTextEnd;
+    case diRunOrParagraphOrEnd:
+      return type == diRun || type == diParagraph || type == diTextEnd;
+    default:
+      return type == nTypeOrClass;
+  }
 }
 
 ME_DisplayItem *ME_FindItemBack(ME_DisplayItem *di, ME_DIType nTypeOrClass)


More information about the wine-patches mailing list