OcMiscLib: Unroll pattern matching loop
@@ -27,7 +27,6 @@ FindPattern (
IN INT32 DataOff
)
{
- BOOLEAN Matches;
UINT32 Index;
ASSERT (DataOff >= 0);
@@ -36,21 +35,33 @@ FindPattern (
return -1;
}
+ if (PatternMask == NULL) {
while (DataOff + PatternSize <= DataSize) {
- Matches = TRUE;
for (Index = 0; Index < PatternSize; ++Index) {
- if ((PatternMask == NULL && Data[DataOff + Index] != Pattern[Index])
- || (PatternMask != NULL && (Data[DataOff + Index] & PatternMask[Index]) != Pattern[Index])) {
- Matches = FALSE;
+ if (Data[DataOff + Index] != Pattern[Index]) {
break;
}
}
- if (Matches) {
+ if (Index == PatternSize) {
return DataOff;
}
++DataOff;
}
+ } else {
+ while (DataOff + PatternSize <= DataSize) {
+ for (Index = 0; Index < PatternSize; ++Index) {
+ if ((Data[DataOff + Index] & PatternMask[Index]) != Pattern[Index]) {
+ break;
+ }
+ }
+
+ if (Index == PatternSize) {
+ return DataOff;
+ }
+ ++DataOff;
+ }
+ }
return -1;
}
