Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
06/09/10 16:29:02 (14 years ago)
Author:
epitzer
Message:

Accelerate persistence: (#646)

  • dynamically compile field and property accessors
  • enable caching of compiled field and property accessors
  • delay costly custom attribute retrieval by checking signatures first
  • implement custom List<double> serializer
  • log deserialization time span
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Persistence/3.3/Default/Xml/Compact/DoubleList2XmlSerializer.cs

    r3742 r3913  
    2323using System.Collections.Generic;
    2424using System;
     25using System.Linq;
    2526using HeuristicLab.Persistence.Core;
    2627using HeuristicLab.Persistence.Default.Xml.Primitive;
     28using System.Text;
    2729
    2830namespace HeuristicLab.Persistence.Default.Xml.Compact {
    2931
    30   internal sealed class DoubleList2XmlSerializer : NumberEnumeration2XmlSerializerBase<List<double>> {
     32  internal sealed class DoubleList2XmlSerializer : CompactXmlSerializerBase<List<double>> {
    3133
    32     protected override void Add(IEnumerable enumeration, object o) {
    33       ((List<double>)enumeration).Add((double)o);
     34    private static readonly char[] separators = new char[] { ';' };
     35
     36    public override XmlString Format(List<double> list) {
     37      StringBuilder sb = new StringBuilder();
     38      foreach (var d in list) {
     39        sb.Append(Double2XmlSerializer.FormatG17(d)).Append(';');
     40      }
     41      return new XmlString(sb.ToString());
    3442    }
    3543
    36     protected override IEnumerable Instantiate() {
    37       return new List<double>();
     44    public override List<double> Parse(XmlString data) {
     45      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) {
     49          list.Add(Double2XmlSerializer.ParseG17(value));
     50        }
     51        return list;
     52      } catch (InvalidCastException e) {
     53        throw new PersistenceException("Invalid element data during reconstruction of List<double>.", e);
     54      } catch (OverflowException e) {
     55        throw new PersistenceException("Overflow during element parsing while trying to reconstruct List<double>.", e);
     56      }
    3857    }
    39 
    40     protected override string FormatValue(object o) {
    41       return Double2XmlSerializer.FormatG17((double)o);
    42     }
    43 
    44     protected override object ParseValue(string o) {
    45       return Double2XmlSerializer.ParseG17(o);
    46     }
    47 
    4858  }
    4959}
Note: See TracChangeset for help on using the changeset viewer.