Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/28/17 09:03:34 (7 years ago)
Author:
pkimmesw
Message:

#2665 Testet Problems, Improved Performance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PushGP/HeuristicLab.PushGP/HeuristicLab.Problems.ProgramSynthesis/Push/Expressions/ExpressionTable.cs

    r15334 r15341  
    175175
    176176    public static Expression GetStatelessExpression<T>() where T : StatelessExpression {
    177       return GetStatelessExpression(typeToNameTable[typeof(T)]);
     177      Expression expression;
     178      var type = typeof(T);
     179
     180      if (StatelessExpressionTable.TryGetValue(type, out expression))
     181        return expression;
     182
     183      throw new NotSupportedException("Expression not supported: " + type.Name);
    178184    }
    179185
    180186    public static Expression GetStatelessExpression(string name) {
    181       if (NameToTypeTable.ContainsKey(name) && StatelessExpressionTable.ContainsKey(NameToTypeTable[name]))
    182         return StatelessExpressionTable[NameToTypeTable[name]];
     187      Type type;
     188      Expression expression;
     189
     190      if (NameToTypeTable.TryGetValue(name, out type) && StatelessExpressionTable.TryGetValue(type, out expression))
     191        return expression;
     192
    183193      throw new NotSupportedException("Expression not supported: " + name);
    184194    }
    185195
    186196    public static bool TryGetStatelessExpression(string name, out Expression expression) {
    187       if (!NameToTypeTable.ContainsKey(name) || !StatelessExpressionTable.ContainsKey(NameToTypeTable[name])) {
     197      Type type;
     198      if (!NameToTypeTable.TryGetValue(name, out type) || !StatelessExpressionTable.TryGetValue(type, out expression)) {
    188199        expression = null;
    189200        return false;
    190201      }
    191202
    192       expression = StatelessExpressionTable[NameToTypeTable[name]];
    193203      return true;
    194204    }
     
    199209
    200210    public static Expression GetStatefulExpression(string name) {
    201       if (NameToTypeTable.ContainsKey(name)) {
    202         Func<Expression> creator;
    203         var type = NameToTypeTable[name];
    204 
    205         if (StatefulExpressionFactory.TryGetValue(type, out creator))
    206           return creator();
     211      Type type;
     212      Func<Expression> creator;
     213
     214      if (NameToTypeTable.TryGetValue(name, out type) && StatefulExpressionFactory.TryGetValue(type, out creator)) {
     215        return creator();
    207216      }
    208217
Note: See TracChangeset for help on using the changeset viewer.