From 4bd209a32fe75e545ed548d7143ff6e2d6639193 Mon Sep 17 00:00:00 2001 From: lindexi Date: Thu, 12 Sep 2024 21:19:25 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=9A=E7=BA=A7?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E5=A4=B1=E8=B4=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bp/MathGraph/MathGraph/MathGraph.cs | 3 ++- Bp/MathGraph/MathGraph/Program.cs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/Bp/MathGraph/MathGraph/MathGraph.cs b/Bp/MathGraph/MathGraph/MathGraph.cs index 64473b170..d6f1b3ecf 100644 --- a/Bp/MathGraph/MathGraph/MathGraph.cs +++ b/Bp/MathGraph/MathGraph/MathGraph.cs @@ -4,11 +4,12 @@ using System.Linq; using System.Text; using System.Threading.Tasks; + using MathGraph.Serialization; namespace MathGraph; -public class MathGraph: ISerializableElement +public class MathGraph : ISerializableElement { public MathGraph() { diff --git a/Bp/MathGraph/MathGraph/Program.cs b/Bp/MathGraph/MathGraph/Program.cs index 7da5b0622..47c0a6477 100644 --- a/Bp/MathGraph/MathGraph/Program.cs +++ b/Bp/MathGraph/MathGraph/Program.cs @@ -51,7 +51,7 @@ public bool TryDeserialize(string value, string? type, [NotNullWhen(true)] out o if (type == typeof(MathGraph).FullName) { var mathGraph = new MathGraph(); - var mathGraphSerializer = mathGraph.GetSerializer(); + var mathGraphSerializer = mathGraph.GetSerializer(this); mathGraphSerializer.Deserialize(value); result = mathGraph; return true; From 63ccd108e2cd7297b5a4e1d1a2349816fb619c49 Mon Sep 17 00:00:00 2001 From: lindexi Date: Fri, 13 Sep 2024 08:45:08 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E7=BB=99=E5=AE=9A?= =?UTF-8?q?=E5=BA=8F=E5=88=97=E5=8C=96=E5=9B=BA=E5=AE=9A=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Bp/MathGraph/MathGraph/MathGraph.cs | 17 ++++++++++++++++- .../Serialization/MathGraphSerializer.cs | 1 + 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Bp/MathGraph/MathGraph/MathGraph.cs b/Bp/MathGraph/MathGraph/MathGraph.cs index d6f1b3ecf..87b273a59 100644 --- a/Bp/MathGraph/MathGraph/MathGraph.cs +++ b/Bp/MathGraph/MathGraph/MathGraph.cs @@ -75,11 +75,26 @@ public void AddBidirectionalEdge(MathGraphElement a, } } - public string Serialize() + string ISerializableElement.Serialize() { var mathGraphSerializer = GetSerializer(); return mathGraphSerializer.Serialize(); } + + internal void StartDeserialize(int elementCount) + { + _elementList.Clear(); + EnsureElementCapacity(elementCount); + } + + /// + /// 序列化使用设置元素的大小 + /// + /// + private void EnsureElementCapacity(int capacity) + { + _elementList.EnsureCapacity(capacity); + } } static class MathGraphElementIdGenerator diff --git a/Bp/MathGraph/MathGraph/Serialization/MathGraphSerializer.cs b/Bp/MathGraph/MathGraph/Serialization/MathGraphSerializer.cs index 9d5e7bdcb..5d1441d69 100644 --- a/Bp/MathGraph/MathGraph/Serialization/MathGraphSerializer.cs +++ b/Bp/MathGraph/MathGraph/Serialization/MathGraphSerializer.cs @@ -142,6 +142,7 @@ public void Deserialize(string json) } var dictionary = new Dictionary>(); + _mathGraph.StartDeserialize(list.Count); foreach (var serializationContext in list) { var elementType = serializationContext.ElementType;