Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 038a4c3

Browse files
Some string.Intern's for minimizing duplicate strings count (#3640)
1 parent 8a8f2b8 commit 038a4c3

File tree

12 files changed

+34
-46
lines changed

12 files changed

+34
-46
lines changed

‎src/NHibernate.Test/Async/NHSpecificTest/NH2898/BinaryFormatterCache.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,31 +23,6 @@ namespace NHibernate.Test.NHSpecificTest.NH2898
2323
public partial class BinaryFormatterCache : CacheBase
2424
{
2525

26-
public override Task<object> GetAsync(object key, CancellationToken cancellationToken)
27-
{
28-
try
29-
{
30-
var entry = _hashtable[key] as byte[];
31-
if (entry == null)
32-
return Task.FromResult<object>(null);
33-
34-
var fmt = new BinaryFormatter
35-
{
36-
#if !NETFX
37-
SurrogateSelector = new SerializationHelper.SurrogateSelector()
38-
#endif
39-
};
40-
using (var stream = new MemoryStream(entry))
41-
{
42-
return Task.FromResult<object>(fmt.Deserialize(stream));
43-
}
44-
}
45-
catch (System.Exception ex)
46-
{
47-
return Task.FromException<object>(ex);
48-
}
49-
}
50-
5126
public override Task PutAsync(object key, object value, CancellationToken cancellationToken)
5227
{
5328
try

‎src/NHibernate/Criterion/EntityProjection.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using NHibernate.Engine;
4-
using NHibernate.Loader;
54
using NHibernate.Loader.Criteria;
65
using NHibernate.Persister.Entity;
76
using NHibernate.SqlCommand;
87
using NHibernate.Type;
8+
using NHibernate.Util;
9+
910
using IQueryable = NHibernate.Persister.Entity.IQueryable;
1011

1112
namespace NHibernate.Criterion
@@ -204,7 +205,7 @@ private void SetFields(ICriteriaQuery criteriaQuery)
204205
subcriteria,
205206
Persister.IdentifierPropertyName ?? string.Empty);
206207

207-
ColumnAliasSuffix = BasicLoader.GenerateSuffix(criteriaQuery.GetIndexForAlias());
208+
ColumnAliasSuffix = StringHelper.GenerateSuffix(criteriaQuery.GetIndexForAlias());
208209

209210
_identifierColumnAliases = Persister.GetIdentifierAliases(ColumnAliasSuffix);
210211

‎src/NHibernate/Hql/Ast/ANTLR/HqlSqlWalker.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ internal string GetSuffix(FromElement fromElement)
485485
return suffix;
486486
}
487487

488-
suffix = _suffixes.Count == 0 ? string.Empty : _suffixes.Count.ToString()+'_';
488+
suffix = _suffixes.Count == 0 ? string.Empty : StringHelper.GenerateSuffix(_suffixes.Count);
489489
_suffixes.Add(fromElement, suffix);
490490

491491
return suffix;

‎src/NHibernate/Hql/Ast/ANTLR/Tree/FromElementType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -532,7 +532,7 @@ private static string GetSuffix(int size, int sequence)
532532

533533
private static string GenerateSuffix(int size, int k)
534534
{
535-
String suffix = size == 1 ? "" : k.ToString()+'_';
535+
String suffix = size == 1 ? "" : StringHelper.GenerateSuffix(k);
536536
return suffix;
537537
}
538538

‎src/NHibernate/Loader/BasicLoader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,15 +99,15 @@ public static string[] GenerateSuffixes(int seed, int length)
9999

100100
for (int i = 0; i < length; i++)
101101
{
102-
suffixes[i] = GenerateSuffix(i + seed);
102+
suffixes[i] = StringHelper.GenerateSuffix(i + seed);
103103
}
104104

105105
return suffixes;
106106
}
107107

108108
public static string GenerateSuffix(int index)
109109
{
110-
return index.ToString()+StringHelper.Underscore;
110+
return StringHelper.GenerateSuffix(index);
111111
}
112112
}
113113
}

‎src/NHibernate/Mapping/Property.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public IEnumerable<ISelectable> ColumnIterator
6666
public string Name
6767
{
6868
get { return name; }
69-
set { name = value; }
69+
set { name = value==null?null:string.Intern(value); }
7070
}
7171

7272
public bool IsComposite
@@ -122,7 +122,7 @@ public CascadeStyle CascadeStyle
122122
public string Cascade
123123
{
124124
get { return cascade; }
125-
set { cascade = value; }
125+
set { cascade = value==null?null:string.Intern(value); }
126126
}
127127

128128
public bool IsUpdateable
@@ -168,7 +168,7 @@ public bool IsOptional
168168
public string PropertyAccessorName
169169
{
170170
get { return propertyAccessorName; }
171-
set { propertyAccessorName = value; }
171+
set { propertyAccessorName = value==null?null:string.Intern(value); }
172172
}
173173

174174
public IGetter GetGetter(System.Type clazz)

‎src/NHibernate/Mapping/SimpleValue.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public IDictionary<string, string> IdentifierGeneratorProperties
6060
public string IdentifierGeneratorStrategy
6161
{
6262
get { return identifierGeneratorStrategy; }
63-
set { identifierGeneratorStrategy = value; }
63+
set { identifierGeneratorStrategy = value==null?null:string.Intern(value); }
6464
}
6565

6666
public virtual bool IsComposite
@@ -127,7 +127,7 @@ public string TypeName
127127
if ((typeName == null && value != null) || (typeName != null && !typeName.Equals(value)))
128128
{
129129
// the property change
130-
typeName = value;
130+
typeName = value==null?null:string.Intern(value);
131131
type = null; // invalidate type
132132
}
133133
}
@@ -353,7 +353,8 @@ public virtual void SetTypeUsingReflection(string className, string propertyName
353353
}
354354
try
355355
{
356-
typeName = ReflectHelper.ReflectedPropertyClass(className, propertyName, accesorName).AssemblyQualifiedName;
356+
var aqn = ReflectHelper.ReflectedPropertyClass(className, propertyName, accesorName).AssemblyQualifiedName;
357+
typeName = aqn == null ? null : string.Intern(aqn);
357358
}
358359
catch (HibernateException he)
359360
{
@@ -372,7 +373,8 @@ public virtual void SetTypeUsingReflection(System.Type propertyOwnerType, string
372373
}
373374
try
374375
{
375-
typeName = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName).AssemblyQualifiedName;
376+
var aqn = ReflectHelper.ReflectedPropertyClass(propertyOwnerType, propertyName, accessorName).AssemblyQualifiedName;
377+
typeName = aqn == null ? null : string.Intern(aqn);
376378
}
377379
catch (HibernateException he)
378380
{

‎src/NHibernate/Persister/Entity/AbstractEntityPersister.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2376,14 +2376,14 @@ protected void InitSubclassPropertyAliasesMap(PersistentClass model)
23762376
{
23772377
if (entityMetamodel.HasNonIdentifierPropertyNamedId)
23782378
{
2379-
subclassPropertyAliases[EntityPersister.EntityID + "." + idPropertyNames[i]] = new string[] { idAliases[i] };
2380-
subclassPropertyColumnNames[EntityPersister.EntityID + "." + IdentifierPropertyName + "." + idPropertyNames[i]] = new string[] { idColumnNames[i] };
2379+
subclassPropertyAliases[string.Intern(EntityPersister.EntityID + "." + idPropertyNames[i])] = new string[] { idAliases[i] };
2380+
subclassPropertyColumnNames[string.Intern(EntityPersister.EntityID + "." + IdentifierPropertyName + "." + idPropertyNames[i])] = new string[] { idColumnNames[i] };
23812381
}
23822382
// if (hasIdentifierProperty() && !ENTITY_ID.equals( getIdentifierPropertyName() ) ) {
23832383
if (HasIdentifierProperty)
23842384
{
2385-
subclassPropertyAliases[IdentifierPropertyName + "." + idPropertyNames[i]] = new string[] { idAliases[i] };
2386-
subclassPropertyColumnNames[IdentifierPropertyName + "." + idPropertyNames[i]] = new string[] { idColumnNames[i] };
2385+
subclassPropertyAliases[string.Intern(IdentifierPropertyName + "." + idPropertyNames[i])] = new string[] { idAliases[i] };
2386+
subclassPropertyColumnNames[string.Intern(IdentifierPropertyName + "." + idPropertyNames[i])] = new string[] { idColumnNames[i] };
23872387
}
23882388
else
23892389
{

‎src/NHibernate/Persister/Entity/AbstractPropertyMapping.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ private static string ExtendPath(string path, string property)
211211
if (string.IsNullOrEmpty(path))
212212
return property;
213213

214-
return StringHelper.Qualify(path, property);
214+
return string.Intern(StringHelper.Qualify(path, property));
215215
}
216216

217217
public string[] GetColumnNames(string propertyName)

‎src/NHibernate/Tuple/Entity/EntityMetamodel.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -449,7 +449,7 @@ private void MapIdentifierPropertyTypes(string path, IType propertyType)
449449
for (var i = 0; i < componentType.PropertyNames.Length; i++)
450450
{
451451
MapIdentifierPropertyTypes(
452-
!string.IsNullOrEmpty(path) ? $"{path}.{componentType.PropertyNames[i]}" : componentType.PropertyNames[i],
452+
!string.IsNullOrEmpty(path) ? string.Intern($"{path}.{componentType.PropertyNames[i]}") : componentType.PropertyNames[i],
453453
componentType.Subtypes[i]);
454454
}
455455
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /