[Mono-dev] Re: [Mono-patches] r56477 - trunk/mcs/class/corlib/System

Eyal Alaluf eyala at mainsoft.com
Sun Feb 5 07:05:40 EST 2006


Hi, Gonzalo.

Wouldn't it make sense to make the Ordinal case inside GetCultureForOption
return InvariantCulture? Returning CurrentCulture means an extra TLS lookup.
Original code:
> +		CultureInfo GetCultureForOption (StringComparison comp)
> +		{
> +			switch (comp) {
> +			case StringComparison.InvariantCulture:
> +			case StringComparison.InvariantCultureIgnoreCase:
> +				return CultureInfo.InvariantCulture;
> +			case StringComparison.CurrentCulture:
> +			case StringComparison.CurrentCultureIgnoreCase:
> +			case StringComparison.Ordinal:
> +			case StringComparison.OrdinalIgnoreCase:
> +				return CultureInfo.CurrentCulture;
Possible change:
> +		CultureInfo GetCultureForOption (StringComparison comp)
> +		{
> +			switch (comp) {
> +			case StringComparison.InvariantCulture:
> +			case StringComparison.InvariantCultureIgnoreCase:
> +			case StringComparison.Ordinal:
> +			case StringComparison.OrdinalIgnoreCase:
> +				return CultureInfo.InvariantCulture;
> +			case StringComparison.CurrentCulture:
> +			case StringComparison.CurrentCultureIgnoreCase:
> +				return CultureInfo.CurrentCulture;

Eyal.

On Thu, 2 Feb 2006, Gonzalo Paniagua wrote:

> Date: Thu,  2 Feb 2006 11:36:10 -0500 (EST)
> From: Gonzalo Paniagua <mono-patches-list at lists.ximian.com>
> To: mono-patches at lists.ximian.com, ximian.monolist at gmail.com,
>     mono-patches-list at googlegroups.com
> Subject: [Mono-patches] r56477 - trunk/mcs/class/corlib/System
> 
> Author: gonzalo
> Date: 2006-02-02 11:36:09 -0500 (Thu, 02 Feb 2006)
> New Revision: 56477
>
> Modified:
>   trunk/mcs/class/corlib/System/ChangeLog
>   trunk/mcs/class/corlib/System/String.cs
> Log:
> 2006-02-02 Gonzalo Paniagua Javier <gonzalo at ximian.com>
>
> 	* String.cs: implement 2.0 StartsWith and EndsWith new overloads. Based
> 	on a patch by Thong Nguyen.
>
>
>
> Modified: trunk/mcs/class/corlib/System/ChangeLog
> ===================================================================
> --- trunk/mcs/class/corlib/System/ChangeLog	2006-02-02 16:12:47 UTC (rev 56476)
> +++ trunk/mcs/class/corlib/System/ChangeLog	2006-02-02 16:36:09 UTC (rev 56477)
> @@ -1,3 +1,8 @@
> +2006-02-02 Gonzalo Paniagua Javier <gonzalo at ximian.com>
> +
> +	* String.cs: implement 2.0 StartsWith and EndsWith new overloads. Based
> +	on a patch by Thong Nguyen.
> +
> 2006-01-31  Zoltan Varga  <vargaz at gmail.com>
>
> 	* String.cs: Implement one of the new net 2.0 Split methods.
>
> Modified: trunk/mcs/class/corlib/System/String.cs
> ===================================================================
> --- trunk/mcs/class/corlib/System/String.cs	2006-02-02 16:12:47 UTC (rev 56476)
> +++ trunk/mcs/class/corlib/System/String.cs	2006-02-02 16:36:09 UTC (rev 56477)
> @@ -925,6 +925,63 @@
> 		}
>
> #if NET_2_0
> +		CompareOptions GetCompareOptions (StringComparison comp)
> +		{
> +			switch (comp) {
> +			case StringComparison.InvariantCulture:
> +			case StringComparison.CurrentCulture:
> +				return CompareOptions.None;
> +			case StringComparison.CurrentCultureIgnoreCase:
> +			case StringComparison.InvariantCultureIgnoreCase:
> +				return CompareOptions.IgnoreCase;
> +			case StringComparison.Ordinal:
> +				return CompareOptions.Ordinal;
> +			case StringComparison.OrdinalIgnoreCase:
> +				return CompareOptions.OrdinalIgnoreCase;
> +			default:
> +				return 0; // If GetCultureForOption returns null, we never call this one.
> +			}
> +		}
> +
> +		CultureInfo GetCultureForOption (StringComparison comp)
> +		{
> +			switch (comp) {
> +			case StringComparison.InvariantCulture:
> +			case StringComparison.InvariantCultureIgnoreCase:
> +				return CultureInfo.InvariantCulture;
> +			case StringComparison.CurrentCulture:
> +			case StringComparison.CurrentCultureIgnoreCase:
> +			case StringComparison.Ordinal:
> +			case StringComparison.OrdinalIgnoreCase:
> +				return CultureInfo.CurrentCulture;
> +			default:
> +				return null;
> +			}
> +		}
> +
> +		public bool StartsWith (string value, StringComparison comparisonType)
> +		{
> +			CultureInfo culture = GetCultureForOption (comparisonType);
> +			if (culture == null)
> +				return false;
> +
> +			CompareOptions options = GetCompareOptions (comparisonType);
> +			return culture.CompareInfo.IsPrefix (this, value, options);
> +		}
> +
> +		public bool EndsWith (string value, StringComparison comparisonType)
> +		{
> +			CultureInfo culture = GetCultureForOption (comparisonType);
> +			if (culture == null)
> +				return false;
> +
> +			CompareOptions options = GetCompareOptions (comparisonType);
> +			return culture.CompareInfo.IsSuffix (this, value, options);
> +		}
> +
> +#endif
> +
> +#if NET_2_0
> 		public
> #else
> 		internal
>
> _______________________________________________
> Mono-patches maillist  -  Mono-patches at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-patches
>
>



More information about the Mono-devel-list mailing list