Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/21/10 18:46:04 (14 years ago)
Author:
epitzer
Message:

Estimate or calculate StringBuffer sizes in advance, use iterator over string splits instead of arrays. (#1138)

Location:
trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/CompactNumberArray2StringSerializer.cs

    r3742 r3937  
    2121
    2222using System;
     23using System.Linq;
    2324using HeuristicLab.Persistence.Interfaces;
    2425using HeuristicLab.Persistence.Core;
     
    2829using System.Text;
    2930using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     31using HeuristicLab.Persistence.Auxiliary;
    3032
    3133namespace HeuristicLab.Persistence.Default.CompositeSerializers {
     
    5860      int[] lengths = new int[a.Rank];
    5961      int[] lowerBounds = new int[a.Rank];
    60       StringBuilder sb = new StringBuilder();
     62      StringBuilder sb = new StringBuilder(a.Rank * 3);
    6163      sb.Append(a.Rank).Append(';');
     64      int capacity = 1;
    6265      for (int i = 0; i < a.Rank; i++) {
    6366        sb.Append(a.GetLength(i)).Append(';');
    6467        lengths[i] = a.GetLength(i);
     68        capacity *= lengths[i];
    6569      }
     70      sb.EnsureCapacity(capacity * 3);
    6671      for (int i = 0; i < a.Rank; i++) {
    6772        sb.Append(a.GetLowerBound(i)).Append(';');
     
    9297        var tagIter = metaInfo.GetEnumerator();
    9398        tagIter.MoveNext();
    94         var valueIter = ((string)tagIter.Current.Value)
    95           .Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)
    96           .GetEnumerator();
     99        var valueIter = ((string)tagIter.Current.Value).GetSplitEnumerator(';');
    97100        valueIter.MoveNext();
    98101        int rank = int.Parse((string)valueIter.Current);
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/CompositeSerializers/NumberEnumerable2StringSerializer.cs

    r3742 r3937  
    9393    }
    9494
     95    private static object[] emptyArgs = new object[0];
    9596    public IEnumerable<Tag> Decompose(object obj) {
    9697      Type type = obj.GetType();
     
    102103          iMap.InterfaceMethods,
    103104          enumerable.GetMethod("GetEnumerator"))];
    104       object[] empty = new object[] { };
    105       object genericEnumerator = getEnumeratorMethod.Invoke(obj, empty);
     105      object genericEnumerator = getEnumeratorMethod.Invoke(obj, emptyArgs);
    106106      MethodInfo moveNextMethod = genericEnumerator.GetType().GetMethod("MoveNext");
    107107      PropertyInfo currentProperty = genericEnumerator.GetType().GetProperty("Current");
    108108      StringBuilder sb = new StringBuilder();
    109       while ((bool)moveNextMethod.Invoke(genericEnumerator, empty))
     109      while ((bool)moveNextMethod.Invoke(genericEnumerator, emptyArgs))
    110110        sb.Append(
    111111          numberConverter.Format(
Note: See TracChangeset for help on using the changeset viewer.