Minor performance improvements

This commit is contained in:
niksedk 2014-08-30 20:10:41 +02:00
parent 1244287821
commit 52fa865572
3 changed files with 5 additions and 5 deletions

View File

@ -151,9 +151,9 @@ namespace Nikse.SubtitleEdit.Forms
string textToLower = text.ToLower();
foreach (string name in namesEtcList)
{
if (textToLower.Contains(name.ToLower())) // Optimization - Contains is much faster than IndexOf
{
int startIndex = textToLower.IndexOf(name.ToLower(), StringComparison.Ordinal);
int startIndex = textToLower.IndexOf(name.ToLower(), StringComparison.Ordinal);
if (startIndex >= 0)
{
while (startIndex >= 0 && startIndex < text.Length &&
textToLower.Substring(startIndex).Contains(name.ToLower()) && name.Length > 1 && name != name.ToLower())
{

View File

@ -276,7 +276,7 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
if (textToLower.Contains(" class="))
{
var className = new StringBuilder();
int startClass = textToLower.IndexOf(" class=");
int startClass = textToLower.IndexOf(" class=", StringComparison.Ordinal);
int indexClass = startClass + 7;
while (indexClass < textToLower.Length && (Utilities.LowercaseLettersWithNumbers + "'\"").Contains(textToLower[indexClass].ToString()))
{

View File

@ -2296,7 +2296,7 @@ namespace Nikse.SubtitleEdit.Logic
foreach (string s in namesEtcMultiWordList)
{
if (s.Contains(word) && text.Contains(s))
if (s.IndexOf(word, StringComparison.Ordinal) >= 0 && text.IndexOf(s, StringComparison.Ordinal) >= 0)
{
if (s.StartsWith(word + " ") || s.EndsWith(" " + word) || s.Contains(" " + word + " "))
return true;