From 93a65c9f7de52a49013fe8d8bd356c35578f11b4 Mon Sep 17 00:00:00 2001 From: neuecc Date: Sun, 11 Dec 2016 21:28:00 +0900 Subject: [PATCH] can serialize zero member struct, improve Unity struct formatter serialization performance --- nuget/ZeroFormatter.Interfaces.nuspec | 2 +- nuget/ZeroFormatter.Unity.nuspec | 4 +- nuget/ZeroFormatter.nuspec | 6 +- nuget/check_zfc.bat | 2 +- nuget/push.bat | 6 +- .../Properties/AssemblyInfo.cs | 4 +- sandbox/Sandbox.NETCore/project.json | 6 +- sandbox/Sandbox.NETCore/project.lock.json | 14 +- .../Sandbox.Shared/Properties/AssemblyInfo.cs | 4 +- sandbox/Sandbox.Shared/Sandbox.Shared.csproj | 4 +- sandbox/Sandbox.Shared/ZeroArgument.cs | 17 ++ sandbox/Sandbox/Program.cs | 11 +- sandbox/Sandbox/Properties/AssemblyInfo.cs | 4 +- .../source.extension.vsixmanifest | 2 +- .../GeneratorPartial.cs | 16 ++ .../Properties/AssemblyInfo.cs | 4 +- .../StructGenerator.cs | 91 ++++--- .../StructGenerator.tt | 5 +- .../project.json | 2 +- .../Properties/AssemblyInfo.cs | 4 +- src/ZeroFormatter.NETCore/project.json | 4 +- src/ZeroFormatter.NETCore/project.lock.json | 6 +- .../Formatters/DynamicFormatter.cs | 83 ++++--- src/ZeroFormatter/Properties/AssemblyInfo.cs | 7 +- .../ZeroFormatter.NETCore.Tests/project.json | 8 +- .../project.lock.json | 232 +++++++++--------- .../Properties/AssemblyInfo.cs | 4 +- tests/ZeroFormatter.Tests/ZeroArgumentTest.cs | 4 + .../Assets/Dlls/Sandbox.Shared.dll | Bin 31232 -> 31744 bytes .../Assets/Dlls/ZeroFormatter.Interfaces.dll | Bin 16896 -> 16896 bytes .../Assets/Dlls/ZeroFormatter.dll | Bin 103936 -> 103936 bytes .../Assets/Dlls/ZeroFormatter.dll.mdb | Bin 40860 -> 40946 bytes .../Assets/Dlls/ZeroFormatter.dll.mdb.meta | 2 +- .../Assets/Scripts/Tests/ZeroArgumentTest.cs | 28 +++ .../Scripts/Tests/ZeroArgumentTest.cs.meta | 12 + .../Assets/Scripts/Tests/_UnitTestLoader.cs | 1 + .../Assets/ZeroFormatterGenerated.cs | 166 ++++++++++++- .../Assets/gmcs.rsp.meta | 8 + .../Assets/smcs.rsp.meta | 8 + .../ZeroFormatter.UnityTests.CSharp.csproj | 23 +- 40 files changed, 546 insertions(+), 258 deletions(-) create mode 100644 sandbox/Sandbox.Shared/ZeroArgument.cs create mode 100644 tests/ZeroFormatter.UnityTests/Assets/Scripts/Tests/ZeroArgumentTest.cs create mode 100644 tests/ZeroFormatter.UnityTests/Assets/Scripts/Tests/ZeroArgumentTest.cs.meta create mode 100644 tests/ZeroFormatter.UnityTests/Assets/gmcs.rsp.meta create mode 100644 tests/ZeroFormatter.UnityTests/Assets/smcs.rsp.meta diff --git a/nuget/ZeroFormatter.Interfaces.nuspec b/nuget/ZeroFormatter.Interfaces.nuspec index 7ad0f95..c777f68 100644 --- a/nuget/ZeroFormatter.Interfaces.nuspec +++ b/nuget/ZeroFormatter.Interfaces.nuspec @@ -2,7 +2,7 @@ ZeroFormatter.Interfaces - 1.5.4 + 1.5.5 ZeroFormatter.Interfaces neuecc y.neuecc diff --git a/nuget/ZeroFormatter.Unity.nuspec b/nuget/ZeroFormatter.Unity.nuspec index 8a085f2..2dca676 100644 --- a/nuget/ZeroFormatter.Unity.nuspec +++ b/nuget/ZeroFormatter.Unity.nuspec @@ -2,7 +2,7 @@ ZeroFormatter.Unity - 1.5.4 + 1.5.5 ZeroFormatter.Unity neuecc y.neuecc @@ -17,7 +17,7 @@ - + diff --git a/nuget/ZeroFormatter.nuspec b/nuget/ZeroFormatter.nuspec index eeaae4a..511a945 100644 --- a/nuget/ZeroFormatter.nuspec +++ b/nuget/ZeroFormatter.nuspec @@ -2,7 +2,7 @@ ZeroFormatter - 1.5.4 + 1.5.5 ZeroFormatter neuecc y.neuecc @@ -17,10 +17,10 @@ - + - + diff --git a/nuget/check_zfc.bat b/nuget/check_zfc.bat index e17619b..bba133d 100644 --- a/nuget/check_zfc.bat +++ b/nuget/check_zfc.bat @@ -1 +1 @@ -zfc -i "C:\Users\y.kawai\Documents\neuecc\ZeroFormatter\sandbox\Sandbox.Shared\Sandbox.Shared.csproj" -o "C:\Users\y.kawai\Documents\neuecc\ZeroFormatter\tests\ZeroFormatter.UnityTests\Assets\ZeroFormatterGenerated.cs" -c UNITY -u \ No newline at end of file +zfc -i "C:\Users\neuecc\Documents\Git\neuecc\ZeroFormatter\sandbox\Sandbox.Shared\Sandbox.Shared.csproj" -o "C:\Users\neuecc\Documents\Git\neuecc\ZeroFormatter\tests\ZeroFormatter.UnityTests\Assets\ZeroFormatterGenerated.cs" -c UNITY -u \ No newline at end of file diff --git a/nuget/push.bat b/nuget/push.bat index 61e49d1..e57a084 100644 --- a/nuget/push.bat +++ b/nuget/push.bat @@ -1,4 +1,4 @@ REM nuget push ZeroFormatter.Analyzer.1.1.1.0.nupkg -Source https://www.nuget.org/api/v2/package -nuget push ZeroFormatter.1.5.4.nupkg -Source https://www.nuget.org/api/v2/package -nuget push ZeroFormatter.Interfaces.1.5.4.nupkg -Source https://www.nuget.org/api/v2/package -nuget push ZeroFormatter.Unity.1.5.4.nupkg -Source https://www.nuget.org/api/v2/package +nuget push ZeroFormatter.1.5.5.nupkg -Source https://www.nuget.org/api/v2/package +nuget push ZeroFormatter.Interfaces.1.5.5.nupkg -Source https://www.nuget.org/api/v2/package +nuget push ZeroFormatter.Unity.1.5.5.nupkg -Source https://www.nuget.org/api/v2/package diff --git a/sandbox/PerformanceComparison/Properties/AssemblyInfo.cs b/sandbox/PerformanceComparison/Properties/AssemblyInfo.cs index c28be89..bf46cda 100644 --- a/sandbox/PerformanceComparison/Properties/AssemblyInfo.cs +++ b/sandbox/PerformanceComparison/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.4.0")] -[assembly: AssemblyFileVersion("1.5.4.0")] +[assembly: AssemblyVersion("1.5.5.0")] +[assembly: AssemblyFileVersion("1.5.5.0")] diff --git a/sandbox/Sandbox.NETCore/project.json b/sandbox/Sandbox.NETCore/project.json index 33eb56b..ea52c39 100644 --- a/sandbox/Sandbox.NETCore/project.json +++ b/sandbox/Sandbox.NETCore/project.json @@ -1,5 +1,5 @@ { - "version": "1.5.4-*", + "version": "1.5.5-*", "buildOptions": { "emitEntryPoint": true }, @@ -9,8 +9,8 @@ "type": "platform", "version": "1.0.0" }, - "ZeroFormatter.Interfaces.NETCore": "1.5.4", - "ZeroFormatter.NETCore": "1.5.4" + "ZeroFormatter.Interfaces.NETCore": "1.5.5", + "ZeroFormatter.NETCore": "1.5.5" }, "frameworks": { diff --git a/sandbox/Sandbox.NETCore/project.lock.json b/sandbox/Sandbox.NETCore/project.lock.json index ad83c42..bd1b175 100644 --- a/sandbox/Sandbox.NETCore/project.lock.json +++ b/sandbox/Sandbox.NETCore/project.lock.json @@ -1992,7 +1992,7 @@ "lib/netstandard1.3/_._": {} } }, - "ZeroFormatter.Interfaces.NETCore/1.5.4": { + "ZeroFormatter.Interfaces.NETCore/1.5.5": { "type": "project", "framework": ".NETStandard,Version=v1.1", "dependencies": { @@ -2006,7 +2006,7 @@ "netstandard1.1/ZeroFormatter.Interfaces.NETCore.dll": {} } }, - "ZeroFormatter.NETCore/1.5.4": { + "ZeroFormatter.NETCore/1.5.5": { "type": "project", "framework": ".NETStandard,Version=v1.6", "dependencies": { @@ -2024,7 +2024,7 @@ "System.Text.Encoding": "4.0.11", "System.Text.Encoding.Extensions": "4.0.11", "System.Threading": "4.0.11", - "ZeroFormatter.Interfaces.NETCore": "1.5.4" + "ZeroFormatter.Interfaces.NETCore": "1.5.5" }, "compile": { "netstandard1.6/ZeroFormatter.NETCore.dll": {} @@ -6627,12 +6627,12 @@ "ref/xamarinwatchos10/_._" ] }, - "ZeroFormatter.Interfaces.NETCore/1.5.4": { + "ZeroFormatter.Interfaces.NETCore/1.5.5": { "type": "project", "path": "../../src/ZeroFormatter.Interfaces.NETCore/project.json", "msbuildProject": "../../src/ZeroFormatter.Interfaces.NETCore/ZeroFormatter.Interfaces.NETCore.xproj" }, - "ZeroFormatter.NETCore/1.5.4": { + "ZeroFormatter.NETCore/1.5.5": { "type": "project", "path": "../../src/ZeroFormatter.NETCore/project.json", "msbuildProject": "../../src/ZeroFormatter.NETCore/ZeroFormatter.NETCore.xproj" @@ -6641,8 +6641,8 @@ "projectFileDependencyGroups": { "": [ "Microsoft.NETCore.App >= 1.0.0", - "ZeroFormatter.Interfaces.NETCore >= 1.5.4", - "ZeroFormatter.NETCore >= 1.5.4" + "ZeroFormatter.Interfaces.NETCore >= 1.5.5", + "ZeroFormatter.NETCore >= 1.5.5" ], ".NETCoreApp,Version=v1.0": [] }, diff --git a/sandbox/Sandbox.Shared/Properties/AssemblyInfo.cs b/sandbox/Sandbox.Shared/Properties/AssemblyInfo.cs index 5e022d0..4d58989 100644 --- a/sandbox/Sandbox.Shared/Properties/AssemblyInfo.cs +++ b/sandbox/Sandbox.Shared/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.4.0")] -[assembly: AssemblyFileVersion("1.5.4.0")] +[assembly: AssemblyVersion("1.5.5.0")] +[assembly: AssemblyFileVersion("1.5.5.0")] diff --git a/sandbox/Sandbox.Shared/Sandbox.Shared.csproj b/sandbox/Sandbox.Shared/Sandbox.Shared.csproj index 81f11de..93088ec 100644 --- a/sandbox/Sandbox.Shared/Sandbox.Shared.csproj +++ b/sandbox/Sandbox.Shared/Sandbox.Shared.csproj @@ -12,6 +12,7 @@ v4.5 v3.5 512 + true @@ -41,8 +42,6 @@ - - @@ -59,6 +58,7 @@ + diff --git a/sandbox/Sandbox.Shared/ZeroArgument.cs b/sandbox/Sandbox.Shared/ZeroArgument.cs new file mode 100644 index 0000000..74921af --- /dev/null +++ b/sandbox/Sandbox.Shared/ZeroArgument.cs @@ -0,0 +1,17 @@ + +using ZeroFormatter; + +namespace Sandbox.Shared +{ + [ZeroFormattable] + public class ZeroClass + { + + } + + [ZeroFormattable] + public struct ZeroStruct + { + + } +} diff --git a/sandbox/Sandbox/Program.cs b/sandbox/Sandbox/Program.cs index d3caae0..8d0d866 100644 --- a/sandbox/Sandbox/Program.cs +++ b/sandbox/Sandbox/Program.cs @@ -241,15 +241,18 @@ public class Nest } + [ZeroFormattable] + public struct ZeroA + { + } + class Program { static void Main(string[] args) { - var a = ZeroFormatterSerializer.Convert(new InnerClassA.InnerObject()); - var b = ZeroFormatterSerializer.Convert(new InnerClassB.InnerObject()); + var a = ZeroFormatterSerializer.Serialize(default(ZeroA)); + - Console.WriteLine(a.GetType().FullName); - Console.WriteLine(b.GetType().FullName); } } diff --git a/sandbox/Sandbox/Properties/AssemblyInfo.cs b/sandbox/Sandbox/Properties/AssemblyInfo.cs index 8d6eb56..1c4b12b 100644 --- a/sandbox/Sandbox/Properties/AssemblyInfo.cs +++ b/sandbox/Sandbox/Properties/AssemblyInfo.cs @@ -32,5 +32,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.4.0")] -[assembly: AssemblyFileVersion("1.5.4.0")] +[assembly: AssemblyVersion("1.5.5.0")] +[assembly: AssemblyFileVersion("1.5.5.0")] diff --git a/src/ZeroFormatter.Analyzer.Vsix/source.extension.vsixmanifest b/src/ZeroFormatter.Analyzer.Vsix/source.extension.vsixmanifest index 42ea11d..9742650 100644 --- a/src/ZeroFormatter.Analyzer.Vsix/source.extension.vsixmanifest +++ b/src/ZeroFormatter.Analyzer.Vsix/source.extension.vsixmanifest @@ -1,7 +1,7 @@  - + ZeroFormatterAnalyzer New Launcher of ZeroFormatter.Analyzer diff --git a/src/ZeroFormatter.CodeGenerator/GeneratorPartial.cs b/src/ZeroFormatter.CodeGenerator/GeneratorPartial.cs index c4ec367..ce7d8d2 100644 --- a/src/ZeroFormatter.CodeGenerator/GeneratorPartial.cs +++ b/src/ZeroFormatter.CodeGenerator/GeneratorPartial.cs @@ -87,6 +87,8 @@ public int[] ElementFixedSizes { get { + if (Properties.Length == 0) return new int[0]; + var schemaLastIndex = Properties.Select(x => x.Index).LastOrDefault(); var dict = Properties.Where(x => x.IsFixedSize).ToDictionary(x => x.Index, x => x.FixedSize); var elementSizes = new int[schemaLastIndex + 1]; @@ -101,6 +103,20 @@ public int[] ElementFixedSizes return elementSizes; } } + + public int? GetLength() + { + if (Properties.Length == 0) return 0; + + var sum = 0; + foreach (var item in Properties) + { + if (!item.IsFixedSize) return null; + sum += item.FixedSize; + } + + return sum; + } } public partial class InitializerGenerator diff --git a/src/ZeroFormatter.CodeGenerator/Properties/AssemblyInfo.cs b/src/ZeroFormatter.CodeGenerator/Properties/AssemblyInfo.cs index d66f194..5303103 100644 --- a/src/ZeroFormatter.CodeGenerator/Properties/AssemblyInfo.cs +++ b/src/ZeroFormatter.CodeGenerator/Properties/AssemblyInfo.cs @@ -33,5 +33,5 @@ // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.5.4.0")] -[assembly: AssemblyFileVersion("1.5.4.0")] +[assembly: AssemblyVersion("1.5.5.0")] +[assembly: AssemblyFileVersion("1.5.5.0")] diff --git a/src/ZeroFormatter.CodeGenerator/StructGenerator.cs b/src/ZeroFormatter.CodeGenerator/StructGenerator.cs index 59a612c..8e30f0b 100644 --- a/src/ZeroFormatter.CodeGenerator/StructGenerator.cs +++ b/src/ZeroFormatter.CodeGenerator/StructGenerator.cs @@ -18,7 +18,7 @@ namespace ZeroFormatter.CodeGenerator /// Class to produce the template output /// - #line 1 "C:\Users\y.kawai\Documents\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" + #line 1 "C:\Users\neuecc\Documents\Git\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.TextTemplating", "14.0.0.0")] public partial class StructGenerator : StructGeneratorBase { @@ -31,7 +31,7 @@ public virtual string TransformText() this.Write("#pragma warning disable 618\r\n#pragma warning disable 612\r\n#pragma warning disable" + " 414\r\n#pragma warning disable 168\r\nnamespace "); - #line 10 "C:\Users\y.kawai\Documents\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" + #line 10 "C:\Users\neuecc\Documents\Git\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" this.Write(this.ToStringHelper.ToStringWithCulture(Namespace)); #line default @@ -40,56 +40,56 @@ public virtual string TransformText() "using global::ZeroFormatter.Internal;\r\n using global::ZeroFormatter.Segments;" + "\r\n\r\n"); - #line 17 "C:\Users\y.kawai\Documents\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" + #line 17 "C:\Users\neuecc\Documents\Git\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" foreach(var t in Types) { #line default #line hidden this.Write(" public class "); - #line 18 "C:\Users\y.kawai\Documents\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" + #line 18 "C:\Users\neuecc\Documents\Git\neuecc\ZeroFormatter\src\ZeroFormatter.CodeGenerator\StructGenerator.tt" this.Write(this.ToStringHelper.ToStringWithCulture(t.Name)); #line default #line hidden this.Write("Formatter : Formatter