Skip to content

Commit

Permalink
perf: Guid
Browse files Browse the repository at this point in the history
  • Loading branch information
HMBSbige committed Apr 11, 2022
1 parent ba8fd1d commit 1b8ff95
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 14 deletions.
3 changes: 1 addition & 2 deletions shadowsocks-csharp/Model/Configuration.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Shadowsocks.Enums;
using Shadowsocks.Util;
using Shadowsocks.ViewModel;
using System;
using System.Collections.Generic;
Expand Down Expand Up @@ -553,7 +552,7 @@ public void FixConfiguration()
{
while (id.Contains(server.Id))
{
server.Id = Rng.RandId();
server.Id = Guid.NewGuid().ToString(@"N");
}
id.Add(server.Id);
}
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Model/Server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ public Server()
SubTag = @"";
UdpOverTcp = false;
Enable = true;
Id = Rng.RandId();
Id = Guid.NewGuid().ToString(@"N");
SpeedLog = new ServerSpeedLog();
Index = 0;
IsSelected = false;
Expand Down
16 changes: 5 additions & 11 deletions shadowsocks-csharp/Util/RNG.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
using System;
using System.Security.Cryptography;

namespace Shadowsocks.Util
namespace Shadowsocks.Util;

public static class Rng
{
public static class Rng
public static void RandBytes(byte[] buf, int length = -1)
{
public static void RandBytes(byte[] buf, int length = -1)
{
RandomNumberGenerator.Fill(length < 0 ? buf : buf.AsSpan(0, length));
}

public static string RandId()
{
return Guid.NewGuid().ToString().Replace(@"-", string.Empty);
}
RandomNumberGenerator.Fill(length < 0 ? buf : buf.AsSpan(0, length));
}
}

0 comments on commit 1b8ff95

Please sign in to comment.