- Timestamp:
- 06/21/10 18:46:04 (14 years ago)
- Location:
- trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleList2XmlSerializer.cs
r3913 r3937 27 27 using HeuristicLab.Persistence.Default.Xml.Primitive; 28 28 using System.Text; 29 using HeuristicLab.Persistence.Auxiliary; 29 30 30 31 namespace HeuristicLab.Persistence.Default.Xml.Compact { … … 32 33 internal sealed class DoubleList2XmlSerializer : CompactXmlSerializerBase<List<double>> { 33 34 34 private static readonly char[] separators = new char[] { ';' };35 36 35 public override XmlString Format(List<double> list) { 37 StringBuilder sb = new StringBuilder( );36 StringBuilder sb = new StringBuilder(list.Count * 3); 38 37 foreach (var d in list) { 39 38 sb.Append(Double2XmlSerializer.FormatG17(d)).Append(';'); … … 44 43 public override List<double> Parse(XmlString data) { 45 44 try { 46 var values = data.Data.Split(separators, StringSplitOptions.RemoveEmptyEntries); 47 List<double> list = new List<double>(values.Length); 48 foreach (var value in values) { 45 List<double> list = new List<double>(); 46 foreach (var value in data.Data.EnumerateSplit(';')) { 49 47 list.Add(Double2XmlSerializer.ParseG17(value)); 50 48 } -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlSerializerBase.cs
r3742 r3937 26 26 using HeuristicLab.Persistence.Core; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Persistence.Auxiliary; 28 29 29 30 namespace HeuristicLab.Persistence.Default.Xml.Compact { … … 32 33 internal abstract class NumberArray2XmlSerializerBase<T> : CompactXmlSerializerBase<T> where T : class { 33 34 34 protected virtual string Separator { get { return ";"; } }35 protected virtual char Separator { get { return ';'; } } 35 36 protected abstract string FormatValue(object o); 36 37 protected abstract object ParseValue(string o); … … 40 41 int[] lengths = new int[a.Rank]; 41 42 int[] lowerBounds = new int[a.Rank]; 42 StringBuilder sb = new StringBuilder( );43 StringBuilder sb = new StringBuilder(a.Rank * 3); 43 44 sb.Append(a.Rank); 45 int capacity = 1; 44 46 for (int i = 0; i < a.Rank; i++) { 45 47 sb.Append(Separator); 46 48 sb.Append(a.GetLength(i)); 47 49 lengths[i] = a.GetLength(i); 50 capacity *= lengths[i]; 48 51 } 52 sb.EnsureCapacity(capacity * 3); 49 53 for (int i = 0; i < a.Rank; i++) { 50 54 sb.Append(Separator); … … 71 75 public override T Parse(XmlString x) { 72 76 try { 73 IEnumerator values = 74 x.Data.Split(new[] { Separator }, 75 StringSplitOptions.RemoveEmptyEntries).GetEnumerator(); 77 IEnumerator values = x.Data.GetSplitEnumerator(Separator); 76 78 values.MoveNext(); 77 79 int rank = int.Parse((string)values.Current); -
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberEnumeration2XmlSerializerBase.cs
r3742 r3937 26 26 using HeuristicLab.Persistence.Core; 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 using HeuristicLab.Persistence.Auxiliary; 28 29 29 30 namespace HeuristicLab.Persistence.Default.Xml.Compact { … … 32 33 internal abstract class NumberEnumeration2XmlSerializerBase<T> : CompactXmlSerializerBase<T> where T : IEnumerable { 33 34 34 protected virtual string Separator { get { return ";"; } }35 protected virtual char Separator { get { return ';'; } } 35 36 protected abstract void Add(IEnumerable enumeration, object o); 36 37 protected abstract IEnumerable Instantiate(); … … 50 51 try { 51 52 IEnumerable enumeration = Instantiate(); 52 string[] values = x.Data.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); 53 foreach (var value in values) { 53 foreach (var value in x.Data.EnumerateSplit(Separator)) { 54 54 Add(enumeration, ParseValue(value)); 55 55 }
Note: See TracChangeset
for help on using the changeset viewer.