Skip to content

Commit b1500ea

Browse files
author
Sergey Koshcheyev
committed
NH-902 - Switch from using string.Intern to only looking up the interned string if there is one already, otherwise using the original instance.
SVN: trunk@2639
1 parent 1e7782f commit b1500ea

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

src/NHibernate/Loader/DefaultEntityAliases.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@ private static void Intern( string[] strings )
150150
{
151151
for( int i = 0; i < strings.Length; i++ )
152152
{
153-
strings[ i ] = string.Intern( strings[ i ] );
153+
strings[i] = StringHelper.InternedIfPossible(strings[i]);
154154
}
155155
}
156-
157156
}
158157
}

src/NHibernate/Mapping/Collection.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public bool IsValid( IMapping mapping )
358358
public string ReferencedPropertyName
359359
{
360360
get { return referencedPropertyName; }
361-
set { referencedPropertyName = value == null ? null : string.Intern( value ); }
361+
set { referencedPropertyName = StringHelper.InternedIfPossible(value); }
362362
}
363363

364364
public virtual void Validate( IMapping mapping )
@@ -456,7 +456,7 @@ public IDictionary ManyToManyFilterMap
456456
public string LoaderName
457457
{
458458
get { return loaderName; }
459-
set { loaderName = value == null ? null : string.Intern(value); }
459+
set { loaderName = StringHelper.InternedIfPossible(value); }
460460
}
461461

462462
public bool IsSubselectLoadable

src/NHibernate/Mapping/ToOne.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using NHibernate.Loader;
3+
using NHibernate.Util;
34

45
namespace NHibernate.Mapping
56
{
@@ -37,7 +38,7 @@ public string ReferencedPropertyName
3738
public string ReferencedEntityName
3839
{
3940
get { return referencedEntityName; }
40-
set { referencedEntityName = value == null ? null : string.Intern(value); }
41+
set { referencedEntityName = StringHelper.InternedIfPossible(value); }
4142
}
4243

4344
public bool IsLazy

src/NHibernate/Util/StringHelper.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -624,5 +624,27 @@ public static bool StartsWithCaseInsensitive(string source, string prefix)
624624
{
625625
return CultureInfo.InvariantCulture.CompareInfo.IsPrefix(source, prefix, CompareOptions.IgnoreCase);
626626
}
627+
628+
/// <summary>
629+
/// Returns the interned string equal to <paramref name="str"/> if there is one, or <paramref name="str"/>
630+
/// otherwise.
631+
/// </summary>
632+
/// <param name="str">A <see cref="string" /></param>
633+
/// <returns>A <see cref="string" /></returns>
634+
public static string InternedIfPossible(string str)
635+
{
636+
if (str == null)
637+
{
638+
return null;
639+
}
640+
641+
string interned = string.IsInterned(str);
642+
if (interned != null)
643+
{
644+
return interned;
645+
}
646+
647+
return str;
648+
}
627649
}
628650
}

0 commit comments

Comments
 (0)