Optimize default C# stdlib references to prevent using jit-ed features in a game assembly
This commit is contained in:
@@ -13,6 +13,7 @@ using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using FlaxEditor.GUI.ContextMenu;
|
||||
using FlaxEditor.GUI.Input;
|
||||
using FlaxEditor.GUI.Tree;
|
||||
@@ -38,6 +39,8 @@ namespace FlaxEditor.Utilities
|
||||
public static class Utils
|
||||
{
|
||||
private static readonly StringBuilder CachedSb = new StringBuilder(256);
|
||||
private static readonly Regex IncNameRegex1 = new Regex("(\\d+)$");
|
||||
private static readonly Regex IncNameRegex2 = new Regex("\\((\\d+)\\)$");
|
||||
|
||||
private static readonly string[] MemorySizePostfixes =
|
||||
{
|
||||
@@ -54,6 +57,92 @@ namespace FlaxEditor.Utilities
|
||||
/// </summary>
|
||||
public static readonly string FlaxEngineAssemblyName = "FlaxEngine.CSharp";
|
||||
|
||||
/// <summary>
|
||||
/// Tries to parse number in the name brackets at the end of the value and then increment it to create a new name.
|
||||
/// Supports numbers at the end without brackets.
|
||||
/// </summary>
|
||||
/// <param name="name">The input name.</param>
|
||||
/// <param name="isValid">Custom function to validate the created name.</param>
|
||||
/// <returns>The new name.</returns>
|
||||
public static string IncrementNameNumber(string name, Func<string, bool> isValid)
|
||||
{
|
||||
// Validate input name
|
||||
if (isValid == null || isValid(name))
|
||||
return name;
|
||||
|
||||
// Temporary data
|
||||
int index;
|
||||
int MaxChecks = 10000;
|
||||
string result;
|
||||
|
||||
// Find '<name><num>' case
|
||||
var match = IncNameRegex1.Match(name);
|
||||
if (match.Success && match.Groups.Count == 2)
|
||||
{
|
||||
// Get result
|
||||
string num = match.Groups[0].Value;
|
||||
|
||||
// Parse value
|
||||
if (int.TryParse(num, out index))
|
||||
{
|
||||
// Get prefix
|
||||
string prefix = name.Substring(0, name.Length - num.Length);
|
||||
|
||||
// Generate name
|
||||
do
|
||||
{
|
||||
result = string.Format("{0}{1}", prefix, ++index);
|
||||
|
||||
if (MaxChecks-- < 0)
|
||||
return name + Guid.NewGuid();
|
||||
} while (!isValid(result));
|
||||
|
||||
if (result.Length > 0)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Find '<name> (<num>)' case
|
||||
match = IncNameRegex2.Match(name);
|
||||
if (match.Success && match.Groups.Count == 2)
|
||||
{
|
||||
// Get result
|
||||
string num = match.Groups[0].Value;
|
||||
num = num.Substring(1, num.Length - 2);
|
||||
|
||||
// Parse value
|
||||
if (int.TryParse(num, out index))
|
||||
{
|
||||
// Get prefix
|
||||
string prefix = name.Substring(0, name.Length - num.Length - 2);
|
||||
|
||||
// Generate name
|
||||
do
|
||||
{
|
||||
result = string.Format("{0}({1})", prefix, ++index);
|
||||
|
||||
if (MaxChecks-- < 0)
|
||||
return name + Guid.NewGuid();
|
||||
} while (!isValid(result));
|
||||
|
||||
if (result.Length > 0)
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// Generate name
|
||||
index = 0;
|
||||
do
|
||||
{
|
||||
result = string.Format("{0} {1}", name, index++);
|
||||
|
||||
if (MaxChecks-- < 0)
|
||||
return name + Guid.NewGuid();
|
||||
} while (!isValid(result));
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Formats the amount of bytes to get a human-readable data size in bytes with abbreviation. Eg. 32 kB
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user