Skip to content

Commit

Permalink
Merge pull request #46 from Cysharp/hadashiA/readonly
Browse files Browse the repository at this point in the history
Make the type readonly
  • Loading branch information
hadashiA authored Aug 18, 2023
2 parents 984c3c8 + 7d27aff commit df98414
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/Ulid.Unity/Assets/Scripts/Ulid/Ulid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace System // wa-o, System Namespace!?
#if NETCOREAPP3_1_OR_GREATER
[System.Text.Json.Serialization.JsonConverter(typeof(Cysharp.Serialization.Json.UlidJsonConverter))]
#endif
public partial struct Ulid : IEquatable<Ulid>, IComparable<Ulid>, IComparable
public readonly partial struct Ulid : IEquatable<Ulid>, IComparable<Ulid>, IComparable
#if NET6_0_OR_GREATER
, ISpanFormattable
#endif
Expand Down Expand Up @@ -600,7 +600,7 @@ public Guid ToGuid()
#if NET6_0_OR_GREATER
if (IsVector128Supported && BitConverter.IsLittleEndian)
{
var vector = Unsafe.As<Ulid, Vector128<byte>>(ref this);
var vector = Unsafe.As<Ulid, Vector128<byte>>(ref Unsafe.AsRef(in this));
var shuffled = Shuffle(vector, Vector128.Create((byte)3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15));

return Unsafe.As<Vector128<byte>, Guid>(ref shuffled);
Expand All @@ -613,7 +613,7 @@ public Guid ToGuid()
// |D|C|B|A|...
// ...|F|E|H|G|...
// ...|I|J|K|L|M|N|O|P|
ref var ptr = ref Unsafe.As<Ulid, uint>(ref this);
ref var ptr = ref Unsafe.As<Ulid, uint>(ref Unsafe.AsRef(in this));
var lower = BinaryPrimitives.ReverseEndianness(ptr);
MemoryMarshal.Write(buf, ref lower);

Expand All @@ -626,7 +626,7 @@ public Guid ToGuid()
}
else
{
MemoryMarshal.Write(buf, ref this);
MemoryMarshal.Write(buf, ref Unsafe.AsRef(in this));
}

return MemoryMarshal.Read<Guid>(buf);
Expand Down
8 changes: 4 additions & 4 deletions src/Ulid/Ulid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace System // wa-o, System Namespace!?
#if NETCOREAPP3_1_OR_GREATER
[System.Text.Json.Serialization.JsonConverter(typeof(Cysharp.Serialization.Json.UlidJsonConverter))]
#endif
public partial struct Ulid : IEquatable<Ulid>, IComparable<Ulid>, IComparable
public readonly partial struct Ulid : IEquatable<Ulid>, IComparable<Ulid>, IComparable
#if NET6_0_OR_GREATER
, ISpanFormattable
#endif
Expand Down Expand Up @@ -600,7 +600,7 @@ public Guid ToGuid()
#if NET6_0_OR_GREATER
if (IsVector128Supported && BitConverter.IsLittleEndian)
{
var vector = Unsafe.As<Ulid, Vector128<byte>>(ref this);
var vector = Unsafe.As<Ulid, Vector128<byte>>(ref Unsafe.AsRef(in this));
var shuffled = Shuffle(vector, Vector128.Create((byte)3, 2, 1, 0, 5, 4, 7, 6, 8, 9, 10, 11, 12, 13, 14, 15));

return Unsafe.As<Vector128<byte>, Guid>(ref shuffled);
Expand All @@ -613,7 +613,7 @@ public Guid ToGuid()
// |D|C|B|A|...
// ...|F|E|H|G|...
// ...|I|J|K|L|M|N|O|P|
ref var ptr = ref Unsafe.As<Ulid, uint>(ref this);
ref var ptr = ref Unsafe.As<Ulid, uint>(ref Unsafe.AsRef(in this));
var lower = BinaryPrimitives.ReverseEndianness(ptr);
MemoryMarshal.Write(buf, ref lower);

Expand All @@ -626,7 +626,7 @@ public Guid ToGuid()
}
else
{
MemoryMarshal.Write(buf, ref this);
MemoryMarshal.Write(buf, ref Unsafe.AsRef(in this));
}

return MemoryMarshal.Read<Guid>(buf);
Expand Down

0 comments on commit df98414

Please sign in to comment.