<commit_before>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Palaso.WritingSystems
{
	public class Iso639LanguageCode
	{
		public Iso639LanguageCode(string code, string name, string iso3Code)
		{
			Code = code;
			Name = name;
			ISO3Code = iso3Code;
		}

		internal static string GetNameForSorting(string name)
		{
			return Regex.Replace(name, @"[^\w]", "");
		}

		public string Name { get; set; }

		public string Code { get; set; }    //Iso 639-1 code or Iso 639-3 code if former is not available

		public string ISO3Code { get; set; }

		public static int CompareByName(Iso639LanguageCode x, Iso639LanguageCode y)
		{
			if (x == null)
			{
				if (y == null)
				{
					return 0;
				}
				else
				{
					return -1;
				}
			}
			else
			{
				if (y == null)
				{
					return 1;
				}
				else
				{
					return GetNameForSorting(x.Name).CompareTo(GetNameForSorting(y.Name));
				}
			}
		}

	}
}<commit_msg>Cache the "sortingName" to prevent the slowdown associated with using a regex in the inner-loop of a sort algorithm. (Came up while profiling slow Bloom startup)<commit_after>﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Palaso.WritingSystems
{
	public class Iso639LanguageCode
	{
		//previously, we were spending huge amounts of time during sorting, just calculating this, using a regex
		private string SortingName;

		public Iso639LanguageCode(string code, string name, string iso3Code)
		{
			Code = code;
			Name = name;
			ISO3Code = iso3Code;
		}

		private string _name;
		public string Name
		{
			get { return _name; }
			set
			{
				_name = value;
				SortingName = Regex.Replace(_name, @"[^\w]", "");
			}
		}

		public string Code { get; set; }    //Iso 639-1 code or Iso 639-3 code if former is not available

		public string ISO3Code { get; set; }

		public static int CompareByName(Iso639LanguageCode x, Iso639LanguageCode y)
		{
			if (x == null)
			{
				if (y == null)
				{
					return 0;
				}
				else
				{
					return -1;
				}
			}
			else
			{
				if (y == null)
				{
					return 1;
				}
				else
				{
					return x.SortingName.CompareTo(y.SortingName);
				}
			}
		}

	}
}
{'fraction_non_alphanumeric': 0.10030395136778116, 'fraction_numerical': 0.02344767694311767, 'mean_word_length': 2.6687898089171975, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1358184', 'n_tokens_mistral': 1014, 'n_tokens_neox': 780, 'n_words': 226}