Skip to content

Commit

Permalink
move to dotnet 8
Browse files Browse the repository at this point in the history
  • Loading branch information
UbitUmarov committed Apr 21, 2024
1 parent 43d9983 commit 1b7ad66
Show file tree
Hide file tree
Showing 18 changed files with 158 additions and 80 deletions.
3 changes: 1 addition & 2 deletions OpenMetaverse.StructuredData/LLSD/NotationLLSD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -550,8 +550,7 @@ private static void SerializeLLSDNotationArray(TextWriter writer, OSDArray osdAr
{
writer.Write(arrayBeginNotationMarker);
int lastIndex = osdArray.Count - 1;

for (int idx = 0; idx <= lastIndex; idx++)
for (int idx = 0; idx < osdArray.Count; idx++)
{
SerializeLLSDNotationElement(writer, osdArray[idx]);
if (idx < lastIndex)
Expand Down
4 changes: 2 additions & 2 deletions OpenMetaverse/ObjectPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class UDPPacketBuffer
/// </summary>
public UDPPacketBuffer()
{
Data = new byte[UDPPacketBuffer.BUFFER_SIZE];
Data = GC.AllocateUninitializedArray<byte>(BUFFER_SIZE);
// Will be modified later by BeginReceiveFrom()
RemoteEndPoint = new IPEndPoint(Settings.BIND_ADDR, 0);
}
Expand All @@ -33,7 +33,7 @@ public UDPPacketBuffer()
/// <param name="endPoint">EndPoint of the remote host</param>
public UDPPacketBuffer(IPEndPoint endPoint)
{
Data = new byte[UDPPacketBuffer.BUFFER_SIZE];
Data = GC.AllocateUninitializedArray<byte>(BUFFER_SIZE);
RemoteEndPoint = endPoint;
}

Expand Down
42 changes: 21 additions & 21 deletions OpenMetaverseTypes/OSUTF8.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class osUTF8
internal byte[] m_data;
internal int m_len;

public static readonly osUTF8 Empty = new osUTF8();
public static readonly osUTF8 Empty = new();

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8()
Expand Down Expand Up @@ -187,8 +187,8 @@ public override bool Equals(object obj)
if (obj is osUTF8Slice osUTF8Sliceobj)
return Equals(osUTF8Sliceobj);

if (obj is string)
return Equals((string)obj);
if (obj is string v)
return Equals(v);

if (obj is byte[] byteobj)
return Equals(byteobj);
Expand Down Expand Up @@ -279,7 +279,7 @@ public bool Equals(string s)
{
if (string.IsNullOrEmpty(s))
return m_len == 0;
osUTF8 o = new osUTF8(s);
osUTF8 o = new(s);
return Equals(o);
}

Expand Down Expand Up @@ -656,7 +656,7 @@ public osUTF8Slice SubUTF8(int start)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice SubUTF8(int start, int len)
{
osUTF8Slice oss = new osUTF8Slice(this);
osUTF8Slice oss = new(this);
return oss.SubUTF8(start, len);
}

Expand All @@ -670,91 +670,91 @@ public string SubString(int start)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public string SubString(int start, int len)
{
osUTF8Slice oss = new osUTF8Slice(this);
osUTF8Slice oss = new(this);
return oss.SubString(start, len);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimStart()
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimStart();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimEnd()
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimEnd();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice Trim()
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.Trim();
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimStart(byte b)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimStart(b);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimEnd(byte b)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimEnd(b);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice Trim(byte b)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.Trim(b);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimStart(byte[] v)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimStart(v);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimEnd(byte[] v)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimEnd(v);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice Trim(byte[] v)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.Trim(v);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimStart(char[] v)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimStart(v);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice TrimEnd(char[] v)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.TrimEnd(v);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public osUTF8Slice Trim(char[] v)
{
osUTF8Slice ret = new osUTF8Slice(this);
osUTF8Slice ret = new(this);
return ret.Trim(v);
}

Expand All @@ -777,7 +777,7 @@ public unsafe bool StartsWith(osUTF8 other)

public bool StartsWith(string s)
{
osUTF8 other = new osUTF8(s); // yeack
osUTF8 other = new(s); // yeack
return StartsWith(other);
}

Expand Down Expand Up @@ -898,7 +898,7 @@ public int IndexOf(string s)
{
if (string.IsNullOrEmpty(s))
return -1;
osUTF8 o = new osUTF8(s);
osUTF8 o = new(s);
return IndexOf(o);
}

Expand Down Expand Up @@ -1303,7 +1303,7 @@ public osUTF8 RemoveBytes(int start, int len)
if (start >= m_len)
return Clone();

osUTF8 o = new osUTF8(m_len);
osUTF8 o = new(m_len);
Array.Copy(m_data, 0, o.m_data, 0, start);
o.m_len = start;

Expand Down
41 changes: 35 additions & 6 deletions OpenMetaverseTypes/UtilsConversions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,18 @@ public static short BytesToInt16(ref byte bytes)
return Unsafe.ReadUnaligned<short>(ref bytes);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte BytesToByte(byte[] bytes, int pos)
{
return Unsafe.ReadUnaligned<byte>(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(bytes), pos));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte BytesToByte(byte[] bytes, ref int pos)
{
return Unsafe.ReadUnaligned<byte>(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(bytes), pos++));
}

/// <summary>
/// Convert the first two bytes starting at the given position in
/// native endian ordering to a signed short integer
Expand Down Expand Up @@ -1155,6 +1167,18 @@ public static double BytesToDoubleSafepos(ref byte bytes, int pos)
#endregion BytesTo
#region ToBytes

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ByteToBytes(byte value, byte[] dest, int pos)
{
Unsafe.WriteUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(dest), pos), value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void ByteToBytes(byte value, byte[] dest, ref int pos)
{
Unsafe.WriteUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(dest), pos++), value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static byte[] Int16ToBytes(short value)
{
Expand Down Expand Up @@ -1238,8 +1262,16 @@ public static unsafe void UInt16ToBytes(ushort value, byte* dest)
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UInt16ToBytesBig(ushort value, byte[] dest, int pos)
{
dest[pos] = (byte)(value >> 8);
dest[pos + 1] = (byte)value;
Unsafe.WriteUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(dest), pos), (byte)(value >> 8));
Unsafe.WriteUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(dest), pos + 1), (byte)(value));
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void UInt16ToBytesBig(ushort value, byte[] dest, ref int pos)
{
Unsafe.WriteUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(dest), pos), (byte)(value >> 8));
Unsafe.WriteUnaligned(ref Unsafe.Add(ref MemoryMarshal.GetArrayDataReference(dest), pos + 1), (byte)(value));
pos += 2;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down Expand Up @@ -2365,7 +2397,6 @@ public static int osUTF8GetBytesCount(ReadOnlySpan<char> str)

public static int osUTF8GetBytesCount(ReadOnlySpan<char> str, out int maxsource)
{
maxsource = 0;
char c;
char lastc = (char)0;
int nbytes = 0;
Expand Down Expand Up @@ -2416,7 +2447,6 @@ public static int osUTF8GetBytesCount(ReadOnlySpan<char> str, out int maxsource)

public static int osUTF8GetBytesCount(ReadOnlySpan<char> str, int maxnbytes, out int maxsourcelen)
{
maxsourcelen = 0;
int max2 = maxnbytes - 2;
int max3 = maxnbytes - 3;
int max4 = maxnbytes - 4;
Expand Down Expand Up @@ -3210,8 +3240,7 @@ public static byte SwapNibbles(byte value)
public static IPAddress HostnameToIPv4(string hostname)
{
// Is it already a valid IP?
IPAddress ip;
if (IPAddress.TryParse(hostname, out ip))
if (IPAddress.TryParse(hostname, out IPAddress ip))
return ip;

IPAddress[] hosts = Dns.GetHostEntry(hostname).AddressList;
Expand Down
14 changes: 7 additions & 7 deletions Programs/WinGridProxy/FormWinGridProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ void ProxyManager_OnEventMessageLog(CapsRequest req, CapsStage stage)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(() => ProxyManager_OnEventMessageLog(req, stage)));
this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => ProxyManager_OnEventMessageLog(req, stage)));
}
else
{
Expand Down Expand Up @@ -170,7 +170,7 @@ private void ProxyManager_OnCapabilityAdded(CapInfo cap)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(() => ProxyManager_OnCapabilityAdded(cap)));
this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => ProxyManager_OnCapabilityAdded(cap)));
}
else
{
Expand All @@ -195,7 +195,7 @@ private void ProxyManager_OnLoginResponse(object request, int rsize, Dictionary<
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(() => ProxyManager_OnLoginResponse(request, rsize, headers, host, direction)));
this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => ProxyManager_OnLoginResponse(request, rsize, headers, host, direction)));
}
else
{
Expand Down Expand Up @@ -263,7 +263,7 @@ private void ProxyManager_OnMessageLog(CapsRequest req, CapsStage stage)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(() => ProxyManager_OnMessageLog(req, stage)));
this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => ProxyManager_OnMessageLog(req, stage)));
}
else
{
Expand Down Expand Up @@ -1041,7 +1041,7 @@ private void SearchSessions(FilterOptions opts)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(() => SearchSessions(opts)));
this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => SearchSessions(opts)));
}
else
{
Expand Down Expand Up @@ -1158,7 +1158,7 @@ private void timer1_Tick(object sender, EventArgs e)
{
if (this.InvokeRequired)
{
this.BeginInvoke(new MethodInvoker(() => timer1_Tick(sender, e)));
this.BeginInvoke(new System.Windows.Forms.MethodInvoker(() => timer1_Tick(sender, e)));
}
else
{
Expand Down Expand Up @@ -1296,7 +1296,7 @@ void Instance_MessageLoggedEvent(object sender, MessageLoggedEventArgs e)

if (InvokeRequired)
{
BeginInvoke(new MethodInvoker(() => Instance_MessageLoggedEvent(sender, e)));
BeginInvoke(new System.Windows.Forms.MethodInvoker(() => Instance_MessageLoggedEvent(sender, e)));
}
else
{
Expand Down
16 changes: 6 additions & 10 deletions Programs/mapgenerator/ProtocolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,17 +310,13 @@ public MapPacket Command(byte[] data)
/// <returns></returns>
public MapPacket Command(ushort command, PacketFrequency frequency)
{
switch (frequency)
return frequency switch
{
case PacketFrequency.High:
return HighMaps[command];
case PacketFrequency.Medium:
return MediumMaps[command];
case PacketFrequency.Low:
return LowMaps[command];
}

throw new Exception("Cannot find map for command \"" + command + "\" with frequency \"" + frequency + "\"");
PacketFrequency.High => HighMaps[command],
PacketFrequency.Medium => MediumMaps[command],
PacketFrequency.Low => LowMaps[command],
_ => throw new Exception("Cannot find map for command \"" + command + "\" with frequency \"" + frequency + "\""),
};
}

/// <summary>
Expand Down
Loading

0 comments on commit 1b7ad66

Please sign in to comment.