If I understand this correctly, your code doesn't work. This is because when some characters match and then you find a character that doesn't match, you can't continue checking with the current character, you need to go back to the second character of the current partial match.
An example is
mByteStream = new byte[] { 0, 0, 1 }
,bytes = new byte[] { 0, 1 }
. For this input, the correct result istrue
, but your code returnsfalse
.It looks like this method is part of a type that does other things. I think it would be cleaner if it was in a separate type, taking both arrays as parameters.
When reading the code, it's very easy to confuse
bytes
andmByteStream
,b
andv
. Those names don't mean anything. Much better names would be for exampleneedle
,haystack
,needleIndex
andhaystackIndex
. Having different variables nameshasMatch
andisMatch
is also very confusing.A method that's this complicated would benefit greatly from detailed XML documentation. That way, callers of the method don't need to read its code to know what it does.
- 24.5k
- 4
- 53
- 89