[NTOSKRNL]
authorPierre Schweitzer <pierre@reactos.org>
Sat, 12 Feb 2011 18:39:17 +0000 (18:39 +0000)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 12 Feb 2011 18:39:17 +0000 (18:39 +0000)
For both FsRtlIsNameInExpression & FsRtlIsDbcsInExpression:
- Remove useless checks
- Move redundant sum before loop, so it's done only once
- Fix handling of * wildcard

This fixes failing kmtest tests added in r50614

svn path=/trunk/; revision=50670

reactos/ntoskrnl/fsrtl/dbcsname.c
reactos/ntoskrnl/fsrtl/name.c

index 5b67c30..cdde126 100644 (file)
@@ -160,7 +160,7 @@ NTAPI
 FsRtlIsDbcsInExpression(IN PANSI_STRING Expression,
                         IN PANSI_STRING Name)
 {
-    USHORT ExpressionPosition = 0, NamePosition = 0, MatchingChars;
+    USHORT ExpressionPosition = 0, NamePosition = 0, MatchingChars, StarFound = MAXUSHORT;
     PAGED_CODE();
 
     ASSERT(Name->Length);
@@ -169,34 +169,37 @@ FsRtlIsDbcsInExpression(IN PANSI_STRING Expression,
 
     while (NamePosition < Name->Length && ExpressionPosition < Expression->Length)
     {
-        if ((Expression->Buffer[ExpressionPosition] == Name->Buffer[NamePosition]) ||
-            (Expression->Buffer[ExpressionPosition] == '?') || (Expression->Buffer[ExpressionPosition] == ANSI_DOS_QM) ||
-            (Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT && Name->Buffer[NamePosition] == '.'))
+        if ((Expression->Buffer[ExpressionPosition] == Name->Buffer[NamePosition]))
         {
             NamePosition++;
             ExpressionPosition++;
         }
+        else if ((Expression->Buffer[ExpressionPosition] == '?') || (Expression->Buffer[ExpressionPosition] == ANSI_DOS_QM) ||
+                 (Expression->Buffer[ExpressionPosition] == ANSI_DOS_DOT && Name->Buffer[NamePosition] == '.'))
+        {
+            NamePosition++;
+            ExpressionPosition++;
+            StarFound = MAXUSHORT;
+        }
         else if (Expression->Buffer[ExpressionPosition] == '*')
         {
-            if (ExpressionPosition < (Expression->Length - 1))
+            StarFound = ExpressionPosition++;
+            if (StarFound < (Expression->Length - 1))
             {
-                if (Expression->Buffer[ExpressionPosition+1] != '*' && Expression->Buffer[ExpressionPosition+1] != '?' &&
-                    Expression->Buffer[ExpressionPosition+1] != ANSI_DOS_DOT &&
-                    Expression->Buffer[ExpressionPosition+1] != ANSI_DOS_QM &&
-                    Expression->Buffer[ExpressionPosition+1] != ANSI_DOS_STAR)
+                while (Name->Buffer[NamePosition] != Expression->Buffer[ExpressionPosition] &&
+                       NamePosition < Name->Length)
                 {
-                    while (Name->Buffer[NamePosition] != Expression->Buffer[ExpressionPosition+1] &&
-                           NamePosition < Name->Length) NamePosition++;
+                    NamePosition++;
                 }
             }
             else
             {
                 NamePosition = Name->Length;
             }
-            ExpressionPosition++;
         }
         else if (Expression->Buffer[ExpressionPosition] == ANSI_DOS_STAR)
         {
+            StarFound = MAXUSHORT;
             MatchingChars = NamePosition;
             while (MatchingChars < Name->Length)
             {
@@ -208,6 +211,15 @@ FsRtlIsDbcsInExpression(IN PANSI_STRING Expression,
             }
             ExpressionPosition++;
         }
+        else if (StarFound != MAXUSHORT)
+        {
+            ExpressionPosition = StarFound + 1;
+            while (Name->Buffer[NamePosition] != Expression->Buffer[ExpressionPosition] &&
+                   NamePosition < Name->Length)
+            {
+                NamePosition++;
+            }
+        }
         else
         {
             NamePosition = Name->Length;
index fc4d740..0712a2b 100644 (file)
@@ -22,40 +22,44 @@ FsRtlIsNameInExpressionPrivate(IN PUNICODE_STRING Expression,
                                IN BOOLEAN IgnoreCase,
                                IN PWCHAR UpcaseTable OPTIONAL)
 {
-    USHORT ExpressionPosition = 0, NamePosition = 0, MatchingChars;
+    USHORT ExpressionPosition = 0, NamePosition = 0, MatchingChars, StarFound = MAXUSHORT;
     PAGED_CODE();
 
     ASSERT(!IgnoreCase || UpcaseTable);
 
     while (NamePosition < Name->Length / sizeof(WCHAR) && ExpressionPosition < Expression->Length / sizeof(WCHAR))
     {
-        if ((Expression->Buffer[ExpressionPosition] == (IgnoreCase ? UpcaseTable[Name->Buffer[NamePosition]] : Name->Buffer[NamePosition])) ||
-            (Expression->Buffer[ExpressionPosition] == L'?') || (Expression->Buffer[ExpressionPosition] == DOS_QM) ||
-            (Expression->Buffer[ExpressionPosition] == DOS_DOT && Name->Buffer[NamePosition] == L'.'))
+        if ((Expression->Buffer[ExpressionPosition] == (IgnoreCase ? UpcaseTable[Name->Buffer[NamePosition]] : Name->Buffer[NamePosition])))
         {
             NamePosition++;
             ExpressionPosition++;
         }
+        else if (Expression->Buffer[ExpressionPosition] == L'?' || (Expression->Buffer[ExpressionPosition] == DOS_QM) ||
+                 (Expression->Buffer[ExpressionPosition] == DOS_DOT && Name->Buffer[NamePosition] == L'.'))
+        {
+            NamePosition++;
+            ExpressionPosition++;
+            StarFound = MAXUSHORT;
+        }
         else if (Expression->Buffer[ExpressionPosition] == L'*')
         {
-            if (ExpressionPosition < (Expression->Length / sizeof(WCHAR) - 1))
+            StarFound = ExpressionPosition++;
+            if (StarFound < (Expression->Length / sizeof(WCHAR) - 1))
             {
-                if (Expression->Buffer[ExpressionPosition+1] != L'*' && Expression->Buffer[ExpressionPosition+1] != L'?' &&
-                    Expression->Buffer[ExpressionPosition+1] != DOS_DOT && Expression->Buffer[ExpressionPosition+1] != DOS_QM &&
-                    Expression->Buffer[ExpressionPosition+1] != DOS_STAR)
+                while ((IgnoreCase ? UpcaseTable[Name->Buffer[NamePosition]] : Name->Buffer[NamePosition]) != Expression->Buffer[ExpressionPosition] &&
+                       NamePosition < Name->Length / sizeof(WCHAR))
                 {
-                    while ((IgnoreCase ? UpcaseTable[Name->Buffer[NamePosition]] : Name->Buffer[NamePosition]) != Expression->Buffer[ExpressionPosition+1] &&
-                           NamePosition < Name->Length / sizeof(WCHAR)) NamePosition++;
+                    NamePosition++;
                 }
             }
             else
             {
                 NamePosition = Name->Length / sizeof(WCHAR);
             }
-            ExpressionPosition++;
         }
         else if (Expression->Buffer[ExpressionPosition] == DOS_STAR)
         {
+            StarFound = MAXUSHORT;
             MatchingChars = NamePosition;
             while (MatchingChars < Name->Length / sizeof(WCHAR))
             {
@@ -67,6 +71,15 @@ FsRtlIsNameInExpressionPrivate(IN PUNICODE_STRING Expression,
             }
             ExpressionPosition++;
         }
+        else if (StarFound != MAXUSHORT)
+        {
+            ExpressionPosition = StarFound + 1;
+            while ((IgnoreCase ? UpcaseTable[Name->Buffer[NamePosition]] : Name->Buffer[NamePosition]) != Expression->Buffer[ExpressionPosition] &&
+                       NamePosition < Name->Length / sizeof(WCHAR))
+            {
+                NamePosition++;
+            }
+        }
         else
         {
             NamePosition = Name->Length / sizeof(WCHAR);