Skip to content

Instantly share code, notes, and snippets.

@mgravell
Created July 2, 2020 15:25
Show Gist options
  • Save mgravell/16ed5c0d21a7dd7dfd75a2a22b865331 to your computer and use it in GitHub Desktop.
Save mgravell/16ed5c0d21a7dd7dfd75a2a22b865331 to your computer and use it in GitHub Desktop.
string s = string.Join(",", Enumerable.Repeat("blah", 50));
var charSpan = s.AsSpan();
var vectorized = MemoryMarshal.Cast<char, Vector<ushort>>(charSpan);
Console.WriteLine($"vector chunks: " + vectorized.Length);
foreach(var v in vectorized)
{
if (Vector.EqualsAny(v, spaces)) { ...}
}
// todo: mop up any remainded
// not shown: static readonly Vector<ushort> spaces = new Vector<ushort>(' ');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment