Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
04/25/08 14:46:58 (16 years ago)
Author:
gkronber
Message:

performance tuning of functions framework by removing the need for calling Activator in StorableBase

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Functions/FunctionTree.cs

    r189 r192  
    9393    }
    9494
     95    double[] evaluationResults;
    9596    public virtual double Evaluate(Dataset dataset, int sampleIndex) {
    96       double[] evaluationResults = new double[SubTrees.Count];
     97      // lazy creation of evaluationResults to unburden the GC
     98      if(evaluationResults == null) {
     99        evaluationResults = new double[SubTrees.Count];
     100      }
    97101      for(int i = 0; i < evaluationResults.Length; i++) {
    98102        evaluationResults[i] = SubTrees[i].Evaluate(dataset, sampleIndex);
     
    128132
    129133    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    130       FunctionTree clone = (FunctionTree)base.Clone(clonedObjects);
     134      FunctionTree clone = new FunctionTree();
     135      clonedObjects.Add(clone.Guid, clone);
     136      FillClone(clone, clonedObjects);
     137      return clone;
     138    }
     139
     140    public void FillClone(FunctionTree clone, IDictionary<Guid, object> clonedObjects) {
     141      clone.function = function;
     142      foreach(IVariable variable in localVariables) {
     143        clone.AddVariable((IVariable)variable.Clone(clonedObjects));
     144      }
    131145      foreach(IFunctionTree tree in subTrees) {
    132146        clone.AddSubTree((IFunctionTree)tree.Clone(clonedObjects));
    133147      }
    134       foreach(IVariable variable in localVariables) {
    135         clone.AddVariable((IVariable)variable.Clone(clonedObjects));
    136       }
    137       clone.function = function;
    138       return clone;
    139148    }
    140149
Note: See TracChangeset for help on using the changeset viewer.