- Timestamp:
- 06/24/10 11:17:04 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/NumberArray2XmlSerializerBase.cs
r3937 r3945 27 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 28 using HeuristicLab.Persistence.Auxiliary; 29 using HeuristicLab.Tracing; 30 using System.Collections.Generic; 29 31 30 32 namespace HeuristicLab.Persistence.Default.Xml.Compact { … … 41 43 int[] lengths = new int[a.Rank]; 42 44 int[] lowerBounds = new int[a.Rank]; 43 StringBuilder sb = new StringBuilder( a.Rank * 3);45 StringBuilder sb = new StringBuilder(3 + a.Rank * 3); 44 46 sb.Append(a.Rank); 45 int capacity= 1;47 int nElements = 1; 46 48 for (int i = 0; i < a.Rank; i++) { 47 49 sb.Append(Separator); 48 50 sb.Append(a.GetLength(i)); 49 51 lengths[i] = a.GetLength(i); 50 capacity*= lengths[i];51 } 52 sb.EnsureCapacity( capacity* 3);52 nElements *= lengths[i]; 53 } 54 sb.EnsureCapacity(sb.Length + nElements * 3); 53 55 for (int i = 0; i < a.Rank; i++) { 54 56 sb.Append(Separator); … … 69 71 } 70 72 } 71 } 73 } 72 74 return new XmlString(sb.ToString()); 73 75 } … … 75 77 public override T Parse(XmlString x) { 76 78 try { 77 IEnumerator values = x.Data.GetSplitEnumerator(Separator);79 IEnumerator<string> values = x.Data.GetSplitEnumerator(Separator); 78 80 values.MoveNext(); 79 int rank = int.Parse( (string)values.Current);81 int rank = int.Parse(values.Current); 80 82 int[] lengths = new int[rank]; 81 83 for (int i = 0; i < rank; i++) { 82 84 values.MoveNext(); 83 lengths[i] = int.Parse( (string)values.Current);85 lengths[i] = int.Parse(values.Current); 84 86 } 85 87 int[] lowerBounds = new int[rank]; 86 88 for (int i = 0; i < rank; i++) { 87 89 values.MoveNext(); 88 lowerBounds[i] = int.Parse( (string)values.Current);90 lowerBounds[i] = int.Parse(values.Current); 89 91 } 90 92 Array a = Array.CreateInstance(this.SourceType.GetElementType(), lengths, lowerBounds); 91 93 int[] positions = (int[])lowerBounds.Clone(); 92 while (values.MoveNext()) { 93 a.SetValue(ParseValue( (string)values.Current), positions);94 while (values.MoveNext()) { 95 a.SetValue(ParseValue(values.Current), positions); 94 96 positions[0] += 1; 95 97 for (int i = 0; i < rank - 1; i++) { 96 if (positions[i] >= l engths[i]) {97 positions[i] = 0;98 if (positions[i] >= lowerBounds[i] + lengths[i]) { 99 positions[i] = lowerBounds[i]; 98 100 positions[i + 1] += 1; 99 101 } else {
Note: See TracChangeset
for help on using the changeset viewer.