Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace System // wa-o, System Namespace!?
#if NET8_0_OR_GREATER
, IUtf8SpanFormattable
#endif

{
// https://en.wikipedia.org/wiki/Base32
static readonly char[] Base32Text = "0123456789ABCDEFGHJKMNPQRSTVWXYZ".ToCharArray();
Expand Down Expand Up @@ -145,7 +145,7 @@ internal Ulid(long timestampMilliseconds, XorShift64 random)
this.timestamp5 = Unsafe.Add(ref firstByte, 7);
}
}

// Get first byte of randomness from Ulid Struct.
Unsafe.WriteUnaligned(ref randomness0, random.Next()); // randomness0~7(but use 0~1 only)
Unsafe.WriteUnaligned(ref randomness2, random.Next()); // randomness2~9
Expand Down Expand Up @@ -393,7 +393,7 @@ public string ToBase64(Base64FormattingOptions options = Base64FormattingOptions
try
{
TryWriteBytes(buffer);
return Convert.ToBase64String(buffer, options);
return Convert.ToBase64String(buffer, 0, 16, options);
}
finally
{
Expand Down Expand Up @@ -523,9 +523,9 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
public static bool TryParse(
#if NETSTANDARD2_1_OR_GREATER
[NotNullWhen(true)] string s,
#else
#else
string s,
#endif
#endif
IFormatProvider provider, out Ulid result) => TryParse(s, out result);

//
Expand Down Expand Up @@ -683,15 +683,15 @@ public Guid ToGuid()
}

#if NET6_0_OR_GREATER
private static bool IsVector128Supported
private static bool IsVector128Supported
{
get
get
{
#if NET7_0_OR_GREATER
return Vector128.IsHardwareAccelerated;
#endif
return Sse3.IsSupported;
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector128<byte> Shuffle(Vector128<byte> value, Vector128<byte> mask)
Expand All @@ -712,5 +712,5 @@ private static Vector128<byte> Shuffle(Vector128<byte> value, Vector128<byte> ma
throw new NotImplementedException();
}
#endif
}
}
}
18 changes: 9 additions & 9 deletions src/Ulid/Ulid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace System // wa-o, System Namespace!?
#if NET8_0_OR_GREATER
, IUtf8SpanFormattable
#endif

{
// https://en.wikipedia.org/wiki/Base32
static readonly char[] Base32Text = "0123456789ABCDEFGHJKMNPQRSTVWXYZ".ToCharArray();
Expand Down Expand Up @@ -145,7 +145,7 @@ internal Ulid(long timestampMilliseconds, XorShift64 random)
this.timestamp5 = Unsafe.Add(ref firstByte, 7);
}
}

// Get first byte of randomness from Ulid Struct.
Unsafe.WriteUnaligned(ref randomness0, random.Next()); // randomness0~7(but use 0~1 only)
Unsafe.WriteUnaligned(ref randomness2, random.Next()); // randomness2~9
Expand Down Expand Up @@ -393,7 +393,7 @@ public string ToBase64(Base64FormattingOptions options = Base64FormattingOptions
try
{
TryWriteBytes(buffer);
return Convert.ToBase64String(buffer, options);
return Convert.ToBase64String(buffer, 0, 16, options);
}
finally
{
Expand Down Expand Up @@ -523,9 +523,9 @@ public bool TryFormat(Span<char> destination, out int charsWritten, ReadOnlySpan
public static bool TryParse(
#if NETSTANDARD2_1_OR_GREATER
[NotNullWhen(true)] string s,
#else
#else
string s,
#endif
#endif
IFormatProvider provider, out Ulid result) => TryParse(s, out result);

//
Expand Down Expand Up @@ -683,15 +683,15 @@ public Guid ToGuid()
}

#if NET6_0_OR_GREATER
private static bool IsVector128Supported
private static bool IsVector128Supported
{
get
get
{
#if NET7_0_OR_GREATER
return Vector128.IsHardwareAccelerated;
#endif
return Sse3.IsSupported;
}
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static Vector128<byte> Shuffle(Vector128<byte> value, Vector128<byte> mask)
Expand All @@ -712,5 +712,5 @@ private static Vector128<byte> Shuffle(Vector128<byte> value, Vector128<byte> ma
throw new NotImplementedException();
}
#endif
}
}
}