Skip to content

Commit 839b978

Browse files
committed
Revert "feat: optimize and stabilize string normalization in StringMatcher"
This reverts commit a52a6af.
1 parent a52a6af commit 839b978

1 file changed

Lines changed: 6 additions & 18 deletions

File tree

Flow.Launcher.Infrastructure/StringMatcher.cs

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
using CommunityToolkit.Mvvm.DependencyInjection;
22
using Flow.Launcher.Plugin.SharedModels;
33
using System;
4-
using System.Buffers;
54
using System.Collections.Generic;
6-
using System.ComponentModel.DataAnnotations;
75
using System.Globalization;
86
using System.Linq;
97
using System.Text;
108
using Flow.Launcher.Infrastructure.UserSettings;
11-
using JetBrains.Annotations;
129

1310
namespace Flow.Launcher.Infrastructure
1411
{
@@ -259,23 +256,14 @@ public MatchResult FuzzyMatch(string query, string stringToCompare, MatchOption
259256
};
260257
public static string Normalize(string value)
261258
{
262-
if(string.IsNullOrEmpty(value)) return value;
263-
char[] arrayFromPool = null;
264-
Span<char> buffer = value.Length <= 512 ? stackalloc char[value.Length] : (arrayFromPool = ArrayPool<char>.Shared.Rent(value.Length));
265-
try
259+
Span<char> buffer = stackalloc char[value.Length];
260+
for (int i = 0; i < value.Length; i++)
266261
{
267-
for (int i = 0; i < value.Length; i++)
268-
{
269-
var c = char.ToLowerInvariant(value[i]);
270-
buffer[i] = AccentMap.TryGetValue(c, out var mapped) ? mapped : c;
271-
}
272-
return new string(buffer.Slice(0, value.Length));
273-
}
274-
finally
275-
{
276-
if(arrayFromPool != null)
277-
ArrayPool<char>.Shared.Return(arrayFromPool);
262+
var c = char.ToLowerInvariant(value[i]);
263+
buffer[i] = AccentMap.TryGetValue(c, out var mapped) ? mapped : c;
278264
}
265+
266+
return new string(buffer);
279267
}
280268
private static bool IsAcronym(string stringToCompare, int compareStringIndex)
281269
{

0 commit comments

Comments
 (0)