removed unsafe code from Path
This commit is contained in:
parent
5438347bba
commit
7a495926bf
@ -27,7 +27,7 @@ public class FileLogger : ILogger
|
|||||||
{}
|
{}
|
||||||
|
|
||||||
public FileLogger(IOPath dir, IOPath programName, ILogFormat format)
|
public FileLogger(IOPath dir, IOPath programName, ILogFormat format)
|
||||||
: this($"{dir}{Path.Sep}{programName}_{DateTime.Now.ToString(MyTimeFormat.ForFileNames)}.log", format)
|
: this($"{Path.Concat(dir, programName)}_{DateTime.Now.ToString(MyTimeFormat.ForFileNames)}.log", format)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
public FileLogger(IOPath dir, IOPath programName) : this(dir, programName, new DefaultLogFormat())
|
public FileLogger(IOPath dir, IOPath programName) : this(dir, programName, new DefaultLogFormat())
|
||||||
|
|||||||
@ -17,7 +17,7 @@ public static class TestDtsodV23
|
|||||||
public static void TestBaseTypes()
|
public static void TestBaseTypes()
|
||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("c", "-----[TestDtsodV23/TestBaseTypes]-----");
|
ColoredConsole.WriteLine("c", "-----[TestDtsodV23/TestBaseTypes]-----");
|
||||||
DtsodV23 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}base_types.dtsod"));
|
DtsodV23 dtsod = new(File.ReadAllText(Path.Concat("Dtsod","TestResources","DtsodV23", "base_types.dtsod")));
|
||||||
foreach (var pair in dtsod)
|
foreach (var pair in dtsod)
|
||||||
ColoredConsole.WriteLine("b", pair.Value.GetType().Name + ' ', "w", pair.Key + ' ', "c", pair.Value.ToString());
|
ColoredConsole.WriteLine("b", pair.Value.GetType().Name + ' ', "w", pair.Key + ' ', "c", pair.Value.ToString());
|
||||||
ColoredConsole.WriteLine("g", "test completed");
|
ColoredConsole.WriteLine("g", "test completed");
|
||||||
@ -25,7 +25,7 @@ public static class TestDtsodV23
|
|||||||
public static void TestLists()
|
public static void TestLists()
|
||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("c", "-------[TestDtsodV23/TestLists]-------");
|
ColoredConsole.WriteLine("c", "-------[TestDtsodV23/TestLists]-------");
|
||||||
DtsodV23 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}lists.dtsod"));
|
DtsodV23 dtsod = new(File.ReadAllText(Path.Concat("Dtsod","TestResources","DtsodV23", "lists.dtsod")));
|
||||||
foreach (var pair in dtsod)
|
foreach (var pair in dtsod)
|
||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("b", pair.Value.GetType().Name + ' ', "w", pair.Key, "c",
|
ColoredConsole.WriteLine("b", pair.Value.GetType().Name + ' ', "w", pair.Key, "c",
|
||||||
@ -39,7 +39,7 @@ public static class TestDtsodV23
|
|||||||
public static void TestComplexes()
|
public static void TestComplexes()
|
||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("c", "-----[TestDtsodV23/TestComplexes]-----");
|
ColoredConsole.WriteLine("c", "-----[TestDtsodV23/TestComplexes]-----");
|
||||||
DtsodV23 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}complexes.dtsod"));
|
DtsodV23 dtsod = new(File.ReadAllText(Path.Concat("Dtsod","TestResources","DtsodV23", "complexes.dtsod")));
|
||||||
foreach (var complex in dtsod)
|
foreach (var complex in dtsod)
|
||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("b", complex.Value.GetType().Name + ' ', "w", complex.Key,
|
ColoredConsole.WriteLine("b", complex.Value.GetType().Name + ' ', "w", complex.Key,
|
||||||
@ -55,7 +55,7 @@ public static class TestDtsodV23
|
|||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("c", "--[TestDtsodV23/TestReSerialization]--");
|
ColoredConsole.WriteLine("c", "--[TestDtsodV23/TestReSerialization]--");
|
||||||
var dtsod = new DtsodV23(new DtsodV23(new DtsodV23(
|
var dtsod = new DtsodV23(new DtsodV23(new DtsodV23(
|
||||||
new DtsodV23(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}complexes.dtsod")).ToString()).ToString()).ToString());
|
new DtsodV23(File.ReadAllText(Path.Concat("Dtsod","TestResources","DtsodV23", "complexes.dtsod")))).ToString()).ToString());
|
||||||
ColoredConsole.WriteLine("y", dtsod.ToString());
|
ColoredConsole.WriteLine("y", dtsod.ToString());
|
||||||
ColoredConsole.WriteLine("g", "test completed");
|
ColoredConsole.WriteLine("g", "test completed");
|
||||||
}
|
}
|
||||||
@ -64,7 +64,7 @@ public static class TestDtsodV23
|
|||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("c", "-------[TestDtsodV23/TestSpeed]-------");
|
ColoredConsole.WriteLine("c", "-------[TestDtsodV23/TestSpeed]-------");
|
||||||
IDtsod dtsod=null;
|
IDtsod dtsod=null;
|
||||||
string text = File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}messages.dtsod");
|
string text = File.ReadAllText(Path.Concat("Dtsod","TestResources","DtsodV23", "messages.dtsod"));
|
||||||
LogOperationTime("V21 deserialization",64,()=>dtsod=new DtsodV21(text));
|
LogOperationTime("V21 deserialization",64,()=>dtsod=new DtsodV21(text));
|
||||||
LogOperationTime("V21 serialization", 64, () => _=dtsod.ToString());
|
LogOperationTime("V21 serialization", 64, () => _=dtsod.ToString());
|
||||||
LogOperationTime("V23 deserialization", 64, () => dtsod = new DtsodV23(text));
|
LogOperationTime("V23 deserialization", 64, () => dtsod = new DtsodV23(text));
|
||||||
@ -75,7 +75,7 @@ public static class TestDtsodV23
|
|||||||
public static void TestMemoryConsumption()
|
public static void TestMemoryConsumption()
|
||||||
{
|
{
|
||||||
ColoredConsole.WriteLine("c", "----[TestDtsodV23/TestMemConsumpt]----");
|
ColoredConsole.WriteLine("c", "----[TestDtsodV23/TestMemConsumpt]----");
|
||||||
string text = File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}messages.dtsod");
|
string text = File.ReadAllText(Path.Concat("Dtsod","TestResources","DtsodV23", "messages.dtsod"));
|
||||||
var a = GC.GetTotalMemory(true);
|
var a = GC.GetTotalMemory(true);
|
||||||
var dtsods = new DtsodV23[64];
|
var dtsods = new DtsodV23[64];
|
||||||
for (int i = 0; i < dtsods.Length; i++)
|
for (int i = 0; i < dtsods.Length; i++)
|
||||||
|
|||||||
@ -19,7 +19,7 @@ public static class TestDtsodV24
|
|||||||
public static void TestBaseTypes()
|
public static void TestBaseTypes()
|
||||||
{
|
{
|
||||||
Logger.Log("c", "-----[TestDtsodV24/TestBaseTypes]-----");
|
Logger.Log("c", "-----[TestDtsodV24/TestBaseTypes]-----");
|
||||||
DtsodV24 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}base_types.dtsod"));
|
DtsodV24 dtsod = new(File.ReadAllText($"Path.Concat("Dtsod","TestResources","DtsodV24", "base_types.dtsod")));
|
||||||
foreach (var pair in dtsod)
|
foreach (var pair in dtsod)
|
||||||
Logger.Log("b", pair.ToString());
|
Logger.Log("b", pair.ToString());
|
||||||
Logger.Log("g", "test completed");
|
Logger.Log("g", "test completed");
|
||||||
@ -28,7 +28,7 @@ public static class TestDtsodV24
|
|||||||
public static void TestComplexes()
|
public static void TestComplexes()
|
||||||
{
|
{
|
||||||
Logger.Log("c", "-----[TestDtsodV24/TestComplexes]-----");
|
Logger.Log("c", "-----[TestDtsodV24/TestComplexes]-----");
|
||||||
DtsodV24 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}complexes.dtsod"));
|
DtsodV24 dtsod = new(File.ReadAllText($"Path.Concat("Dtsod","TestResources","DtsodV24", "complexes.dtsod")));
|
||||||
Logger.Log("h", dtsod.ToString());
|
Logger.Log("h", dtsod.ToString());
|
||||||
Logger.Log("g", "test completed");
|
Logger.Log("g", "test completed");
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ public static class TestDtsodV24
|
|||||||
public static void TestLists()
|
public static void TestLists()
|
||||||
{
|
{
|
||||||
Logger.Log("c", "-------[TestDtsodV24/TestLists]-------");
|
Logger.Log("c", "-------[TestDtsodV24/TestLists]-------");
|
||||||
DtsodV24 dtsod = new(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}lists.dtsod"));
|
DtsodV24 dtsod = new(File.ReadAllText($"Path.Concat("Dtsod","TestResources","DtsodV24", "lists.dtsod")));
|
||||||
foreach (KVPair pair in dtsod)
|
foreach (KVPair pair in dtsod)
|
||||||
{
|
{
|
||||||
var list = new Autoarr<Unitype>(pair.value.VoidPtr, false);
|
var list = new Autoarr<Unitype>(pair.value.VoidPtr, false);
|
||||||
@ -61,7 +61,7 @@ public static class TestDtsodV24
|
|||||||
{
|
{
|
||||||
Logger.Log("c", "--[TestDtsodV24/TestReSerialization]--");
|
Logger.Log("c", "--[TestDtsodV24/TestReSerialization]--");
|
||||||
var dtsod = new DtsodV24(new DtsodV24(new DtsodV24(
|
var dtsod = new DtsodV24(new DtsodV24(new DtsodV24(
|
||||||
new DtsodV24(File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}complexes.dtsod")).ToString()).ToString()).ToString());
|
new DtsodV24(File.ReadAllText($"Path.Concat("Dtsod","TestResources","DtsodV24", "complexes.dtsod"))).ToString()).ToString()).ToString()));
|
||||||
Logger.Log("h", dtsod.ToString());
|
Logger.Log("h", dtsod.ToString());
|
||||||
Logger.Log("g", "test completed");
|
Logger.Log("g", "test completed");
|
||||||
}
|
}
|
||||||
@ -70,12 +70,12 @@ public static class TestDtsodV24
|
|||||||
{
|
{
|
||||||
Logger.Log("c", "-------[TestDtsodV24/TestSpeed]-------");
|
Logger.Log("c", "-------[TestDtsodV24/TestSpeed]-------");
|
||||||
IDtsod dtsod=null;
|
IDtsod dtsod=null;
|
||||||
string _text = File.ReadAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV23{Path.Sep}messages.dtsod");
|
string _text = File.ReadAllText(Path.Concat("Dtsod","TestResources","DtsodV23", "messages.dtsod"));
|
||||||
string text = "";
|
string text = "";
|
||||||
LogOperationTime( "V23 to V24 conversion", 32, ()=>
|
LogOperationTime( "V23 to V24 conversion", 32, ()=>
|
||||||
text = DtsodConverter.ConvertVersion(new DtsodV23(_text), DtsodVersion.V24).ToString()
|
text = DtsodConverter.ConvertVersion(new DtsodV23(_text), DtsodVersion.V24).ToString()
|
||||||
);
|
);
|
||||||
File.WriteAllText($"Dtsod{Path.Sep}TestResources{Path.Sep}DtsodV24{Path.Sep}messages.dtsod",text);
|
File.WriteAllText($"Path.Concat("Dtsod","TestResources","DtsodV24", "messages.dtsod",text));
|
||||||
LogOperationTime("V24 deserialization", 64, () => dtsod = new DtsodV24(text));
|
LogOperationTime("V24 deserialization", 64, () => dtsod = new DtsodV24(text));
|
||||||
LogOperationTime("V24 serialization", 64, () => text = dtsod.ToString());
|
LogOperationTime("V24 serialization", 64, () => text = dtsod.ToString());
|
||||||
Logger.Log("g", "test completed");
|
Logger.Log("g", "test completed");
|
||||||
|
|||||||
@ -1,7 +1,3 @@
|
|||||||
#if NETSTANDARD2_1 || NET6_0 || NET7_0 || NET8_0
|
|
||||||
#define USE_SPAN
|
|
||||||
#endif
|
|
||||||
|
|
||||||
using System.Runtime.CompilerServices;
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
namespace DTLib.Filesystem;
|
namespace DTLib.Filesystem;
|
||||||
@ -54,23 +50,16 @@ public static class Path
|
|||||||
}
|
}
|
||||||
|
|
||||||
#if !USE_SPAN
|
#if !USE_SPAN
|
||||||
private static unsafe void CopyTo(this string s, char* b)
|
private static void CopyTo(this string s, char[] b, int startIndex)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < s.Length; i++)
|
for (int i = 0; i < s.Length; i++)
|
||||||
b[i] = s[i];
|
b[startIndex+i] = s[i];
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public static IOPath Concat(params IOPath[] parts)
|
public static IOPath Concat(params IOPath[] parts)
|
||||||
{
|
{
|
||||||
#if USE_SPAN
|
var needSeparator = new bool[parts.Length-1];
|
||||||
Span<bool>
|
|
||||||
#else
|
|
||||||
unsafe
|
|
||||||
{
|
|
||||||
bool*
|
|
||||||
#endif
|
|
||||||
needSeparator = stackalloc bool[parts.Length-1];
|
|
||||||
int lengthSum = 0;
|
int lengthSum = 0;
|
||||||
for (int i = 0; i < parts.Length-1; i++)
|
for (int i = 0; i < parts.Length-1; i++)
|
||||||
{
|
{
|
||||||
@ -83,30 +72,18 @@ public static class Path
|
|||||||
else needSeparator[i] = false;
|
else needSeparator[i] = false;
|
||||||
}
|
}
|
||||||
lengthSum += parts[parts.Length-1].Length;
|
lengthSum += parts[parts.Length-1].Length;
|
||||||
#if USE_SPAN
|
var buffer = new char[lengthSum];
|
||||||
Span<char>
|
parts[0].Str.CopyTo(buffer, 0);
|
||||||
#else
|
|
||||||
char*
|
|
||||||
#endif
|
|
||||||
buffer = stackalloc char[lengthSum];
|
|
||||||
parts[0].Str.CopyTo(buffer);
|
|
||||||
int copiedChars = parts[0].Length;
|
int copiedChars = parts[0].Length;
|
||||||
for (int i = 1; i < parts.Length; i++)
|
for (int i = 1; i < parts.Length; i++)
|
||||||
{
|
{
|
||||||
if (needSeparator[i-1])
|
if (needSeparator[i-1])
|
||||||
buffer[copiedChars++] = Sep;
|
buffer[copiedChars++] = Sep;
|
||||||
#if USE_SPAN
|
parts[i].Str.CopyTo(buffer, copiedChars);
|
||||||
parts[i].Str.CopyTo(buffer.Slice(copiedChars));
|
|
||||||
#else
|
|
||||||
parts[i].Str.CopyTo(buffer+copiedChars);
|
|
||||||
#endif
|
|
||||||
copiedChars += parts[i].Length;
|
copiedChars += parts[i].Length;
|
||||||
}
|
}
|
||||||
|
|
||||||
return new IOPath(new string(buffer), true);
|
return new IOPath(new string(buffer), true);
|
||||||
#if !USE_SPAN
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// returns just dir name or file name with extension
|
/// returns just dir name or file name with extension
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user