[Mono-dev] [Patch] TreeView, TreeNode, TreeNodeCollection

Robert Jordan robertj at gmx.net
Tue Jan 9 14:58:39 EST 2007


Hi Alan,

Alan McGovern wrote:
> This is my first patch, so i want to make sure that everything is alright
> before i go committing. I will provide NUnit tests for the new 
> functionality
> (i'll post the tests here) if everything looks good with the patch.

You should write and test the unit tests on MS.NET even before
starting to code, because MS.NET's docs are often incomplete.

> +#if NET_2_0
> +		public virtual int IndexOfKey(string key)
> +		{
> +			if (string.IsNullOrEmpty(key))
> +				return -1;
> +
> +				// We do a case insensitive comparison to find the key
> +			for (int i = 0; i < nodes.Count; i++)
> +				if (string.Equals(nodes.Name, name, StringComparison.CurrentCultureIgnoreCase))

Does MS.NET really perform a culture-variant comparison?

Also, that's a linear scan. How does MS.NET perform? You may want to
write a test that creates 1000000 nodes and that removes them by
name. If it's an almost instant operation on MS.NET, they are probably
optimizing the lookup using a non-linear (hash table, sorted
list) data type.

> +		public virtual void RemoveByKey(string key)
> +		{
> +			int index = -1;
> +			for (int i = 0; i < nodes.Count; i++)
> +			{
> +				if (!string.Equals(nodes[i].Name,key, StringComparison.CurrentCultureIgnoreCase))
> +					continue;
> +
> +				index = i;
> +				break;
> +			}

Ditto. Additionally, what happens on MS.NET if you remove the
String.Empty key? What happens if the collection has duplicate keys?
Will be the keys deleted all together or just the first/last/random
occurrence?

Robert




More information about the Mono-devel-list mailing list