Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetIndexOfFirstByteToEncode()

unsafe int System.Text.Encodings.Web.OptimizedInboxTextEncoder.GetIndexOfFirstByteToEncode ( ReadOnlySpan< byte > data)
inline

Definition at line 334 of file OptimizedInboxTextEncoder.cs.

335 {
336 int length = data.Length;
337 if (Ssse3.IsSupported || (AdvSimd.Arm64.IsSupported && BitConverter.IsLittleEndian))
338 {
339 int num;
340 fixed (byte* pData = data)
341 {
342 UIntPtr uIntPtr = ((!AdvSimd.Arm64.IsSupported || !BitConverter.IsLittleEndian) ? GetIndexOfFirstByteToEncodeSsse3(pData, (uint)length) : GetIndexOfFirstByteToEncodeAdvSimd64(pData, (uint)length));
343 num = (int)(nuint)uIntPtr;
344 }
345 if (!SpanUtility.IsValidIndex(data, num))
346 {
347 return -1;
348 }
350 {
351 return num;
352 }
353 data = data.Slice(num);
354 }
355 Rune result;
356 int bytesConsumed;
357 while (!data.IsEmpty && Rune.DecodeFromUtf8(data, out result, out bytesConsumed) == OperationStatus.Done && bytesConsumed < 4 && _allowedBmpCodePoints.IsCharAllowed((char)result.Value))
358 {
359 data = data.Slice(bytesConsumed);
360 }
361 if (!data.IsEmpty)
362 {
363 return length - data.Length;
364 }
365 return -1;
366 }
unsafe nuint GetIndexOfFirstByteToEncodeAdvSimd64(byte *pData, nuint lengthInBytes)
unsafe nuint GetIndexOfFirstByteToEncodeSsse3(byte *pData, nuint lengthInBytes)
static bool IsAsciiCodePoint(uint value)
ReadOnlySpan< T > Slice(int start)

References System.Text.Encodings.Web.OptimizedInboxTextEncoder._allowedBmpCodePoints, System.Text.Rune.DecodeFromUtf8(), System.Text.Encodings.Web.OptimizedInboxTextEncoder.GetIndexOfFirstByteToEncodeAdvSimd64(), System.Text.Encodings.Web.OptimizedInboxTextEncoder.GetIndexOfFirstByteToEncodeSsse3(), System.Text.UnicodeUtility.IsAsciiCodePoint(), System.Text.Encodings.Web.AllowedBmpCodePointsBitmap.IsCharAllowed(), System.ReadOnlySpan< T >.IsEmpty, System.BitConverter.IsLittleEndian, System.Runtime.Intrinsics.Arm.AdvSimd.Arm64.IsSupported, System.Runtime.Intrinsics.X86.Ssse3.IsSupported, System.length, System.ReadOnlySpan< T >.Length, System.ReadOnlySpan< T >.Slice(), and System.Text.Rune.Value.

Referenced by System.Text.Encodings.Web.DefaultHtmlEncoder.FindFirstCharacterToEncodeUtf8(), System.Text.Encodings.Web.DefaultJavaScriptEncoder.FindFirstCharacterToEncodeUtf8(), and System.Text.Encodings.Web.DefaultUrlEncoder.FindFirstCharacterToEncodeUtf8().