Repository: files-community/Files
File: src/Files.App/Helpers/NaturalStringComparer.cs (C#)

Code before:
		    {
		        return Compare(x.Span, y.Span, stringComparison);
		    }

		    public static int Compare(ReadOnlySpan<char> x, ReadOnlySpan<char> y, StringComparison stringComparison)
			{
    			// Handle file extensions specially
    			int xExtPos = GetExtensionPosition(x);
    			int yExtPos = GetExtensionPosition(y);
    
    			// If both have extensions, compare the names first
    			if (xExtPos >= 0 && yExtPos >= 0)
    			{
        			var xName = x.Slice(0, xExtPos);
        			var yName = y.Slice(0, yExtPos);
        
        			int nameCompare = CompareWithoutExtension(xName, yName, stringComparison);
        			if (nameCompare != 0)
            			return nameCompare;
            
        			// If names match, compare extensions
        			return x.Slice(xExtPos).CompareTo(y.Slice(yExtPos), stringComparison);
    			}
    
    			// Original comparison logic for non-extension cases
    			return CompareWithoutExtension(x, y, stringComparison);
			}

			private static int CompareWithoutExtension(ReadOnlySpan<char> x, ReadOnlySpan<char> y, StringComparison stringComparison)
			{
				var length = Math.Min(x.Length, y.Length);

				for (var i = 0; i < length; i++)
				{
					while (i < x.Length && i < y.Length && IsIgnorableSeparator(x, i) && IsIgnorableSeparator(y, i))
						i++;

					if (i >= x.Length || i >= y.Length) break;

					if (char.IsDigit(x[i]) && char.IsDigit(y[i]))
					{
						var xOut = GetNumber(x.Slice(i), out var xNumAsSpan);
						var yOut = GetNumber(y.Slice(i), out var yNumAsSpan);

						var compareResult = CompareNumValues(xNumAsSpan, yNumAsSpan);

						if (compareResult != 0) return compareResult;

						i = -1;
						length = Math.Min(xOut.Length, yOut.Length);


Review comment (suggestion):
```suggestion
				// Handle file extensions specially
				int xExtPos = GetExtensionPosition(x);
				int yExtPos = GetExtensionPosition(y);

				// If both have extensions, compare the names first
				if (xExtPos >= 0 && yExtPos >= 0)
				{
		 			var xName = x.Slice(0, xExtPos);
					var yName = y.Slice(0, yExtPos);
		
					int nameCompare = CompareWithoutExtension(xName, yName, stringComparison);
					if (nameCompare != 0)
						return nameCompare;

					// If names match, compare extensions
					return x.Slice(xExtPos).CompareTo(y.Slice(yExtPos), stringComparison);
				}

				// Original comparison logic for non-extension cases
				return CompareWithoutExtension(x, y, stringComparison);
```

Code after:
		    {
		        return Compare(x.Span, y.Span, stringComparison);
		    }

		    public static int Compare(ReadOnlySpan<char> x, ReadOnlySpan<char> y, StringComparison stringComparison)
			{
				// Handle file extensions specially
				int xExtPos = GetExtensionPosition(x);
				int yExtPos = GetExtensionPosition(y);

				// If both have extensions, compare the names first
				if (xExtPos >= 0 && yExtPos >= 0)
				{
		 			var xName = x.Slice(0, xExtPos);
					var yName = y.Slice(0, yExtPos);
		
					int nameCompare = CompareWithoutExtension(xName, yName, stringComparison);
					if (nameCompare != 0)
						return nameCompare;

					// If names match, compare extensions
					return x.Slice(xExtPos).CompareTo(y.Slice(yExtPos), stringComparison);
				}

				// Original comparison logic for non-extension cases
				return CompareWithoutExtension(x, y, stringComparison);
			}

			private static int CompareWithoutExtension(ReadOnlySpan<char> x, ReadOnlySpan<char> y, StringComparison stringComparison)
			{
				var length = Math.Min(x.Length, y.Length);

				for (var i = 0; i < length; i++)
				{
					while (i < x.Length && i < y.Length && IsIgnorableSeparator(x, i) && IsIgnorableSeparator(y, i))
						i++;

					if (i >= x.Length || i >= y.Length) break;

					if (char.IsDigit(x[i]) && char.IsDigit(y[i]))
					{
						var xOut = GetNumber(x.Slice(i), out var xNumAsSpan);
						var yOut = GetNumber(y.Slice(i), out var yNumAsSpan);

						var compareResult = CompareNumValues(xNumAsSpan, yNumAsSpan);

						if (compareResult != 0) return compareResult;

						i = -1;
						length = Math.Min(xOut.Length, yOut.Length);