Skip to content

Commit 57bfa71

Browse files
committed
Added a comment
1 parent 232c6cf commit 57bfa71

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

src/HttpUserAgentParser/HttpUserAgentParser.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,15 @@ private static bool TryExtractVersion(ReadOnlySpan<char> haystack, out Range ran
209209
{
210210
range = default;
211211

212+
// Vectorization is used in a optimistic way and specialized to common (trimmed down) user agents.
213+
// When the first two char-vectors don't yield any success, we fall back to the scalar path.
214+
// This penalized not found versions, but has an advantage for found versions.
215+
// Vector512 is left out, because there are no common inputs with length 128 or more.
216+
//
217+
// Two short (same size as char) vectors are read, then packed to byte vectors on which the
218+
// operation is done. For short / chart the higher byte is not of interest and zero or outside
219+
// the target characters, thus with bytes we can process twice as much elements at once.
220+
212221
if (Vector256.IsHardwareAccelerated && haystack.Length >= 2 * Vector256<short>.Count)
213222
{
214223
ref char ptr = ref MemoryMarshal.GetReference(haystack);

0 commit comments

Comments
 (0)