Optimize default C# stdlib references to prevent using jit-ed features in a game assembly
This commit is contained in:
@@ -4,7 +4,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace FlaxEngine
|
||||
{
|
||||
@@ -260,94 +259,5 @@ namespace FlaxEngine
|
||||
{
|
||||
return s.Replace("\n", "").Replace("\r", "");
|
||||
}
|
||||
|
||||
private static readonly Regex IncNameRegex1 = new Regex("(\\d+)$");
|
||||
private static readonly Regex IncNameRegex2 = new Regex("\\((\\d+)\\)$");
|
||||
|
||||
/// <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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user