mirror of
https://github.com/OrchardCMS/Orchard.git
synced 2025-10-15 19:54:57 +08:00
Perf - optimizing heavily called method
--HG-- branch : perf
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using FluentNHibernate.Conventions;
|
||||
@@ -8,15 +9,15 @@ using Orchard.Environment.ShellBuilders.Models;
|
||||
|
||||
namespace Orchard.Data.Conventions {
|
||||
public class RecordTableNameConvention : IClassConvention {
|
||||
private readonly IEnumerable<RecordBlueprint> _descriptors;
|
||||
private readonly Dictionary<Type, RecordBlueprint> _descriptors;
|
||||
|
||||
public RecordTableNameConvention(IEnumerable<RecordBlueprint> descriptors) {
|
||||
_descriptors = descriptors;
|
||||
_descriptors = descriptors.ToDictionary(d => d.Type);
|
||||
}
|
||||
|
||||
public void Apply(IClassInstance instance) {
|
||||
var desc = _descriptors.Where(d => d.Type == instance.EntityType).SingleOrDefault();
|
||||
if (desc != null) {
|
||||
RecordBlueprint desc;
|
||||
if (_descriptors.TryGetValue(instance.EntityType, out desc)) {
|
||||
instance.Table(desc.TableName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user