Skip to content

Commit 348987f

Browse files
committed
minor perf improvements
1 parent 44a2764 commit 348987f

File tree

4 files changed

+40
-15
lines changed

4 files changed

+40
-15
lines changed

src/DiffEngine.Tests/DiffEngine.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Using Include="DiffEngine" />
1111
<PackageReference Include="MarkdownSnippets.MsBuild" Version="24.5.1" Condition="$(TargetFramework) == 'net7.0'" />
1212
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
13-
<PackageReference Include="Argon" Version="0.4.0" />
13+
<PackageReference Include="Argon" Version="0.5.0" />
1414
<PackageReference Include="Xunit" Version="2.4.2" />
1515
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5" PrivateAssets="all" />
1616
<PackageReference Include="ProjectDefaults" Version="1.0.89" PrivateAssets="all" />

src/DiffEngine/Guard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void AgainstBadExtension(string value, string argumentName)
6060
{
6161
AgainstEmpty(value, argumentName);
6262

63-
if (value.StartsWith("."))
63+
if (value[0] == '.')
6464
{
6565
throw new ArgumentException("Must not start with a period ('.').", argumentName);
6666
}

src/DiffEngine/Tray/JsonEscaping.cs

Lines changed: 37 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,41 @@ static bool IsStartOfScriptTag(string src, int i, char c) =>
2525
i > 0 &&
2626
src[i - 1] == '<';
2727

28-
static bool IsBrokenTailSurrogate(string src, int i, char c) =>
29-
c is
30-
>= '\uDC00' and
31-
<= '\uDFFF' &&
32-
(i == 0 || src[i - 1] < '\uD800' || src[i - 1] > '\uDBFF');
28+
static bool IsBrokenTailSurrogate(string src, int i, char c)
29+
{
30+
if (c is
31+
< '\uDC00' or
32+
> '\uDFFF')
33+
{
34+
return false;
35+
}
3336

34-
static bool IsBrokenLeadSurrogate(string src, int i, char c) =>
35-
c is
36-
>= '\uD800' and
37-
<= '\uDBFF' &&
38-
(i == src.Length - 1 || src[i + 1] < '\uDC00' || src[i + 1] > '\uDFFF');
37+
if (i == 0)
38+
{
39+
return true;
40+
}
41+
42+
var l = src[i - 1];
43+
return l is < '\uD800' or > '\uDBFF';
44+
}
45+
46+
static bool IsBrokenLeadSurrogate(string src, int i, char c)
47+
{
48+
if (c is
49+
< '\uD800' or
50+
> '\uDBFF')
51+
{
52+
return false;
53+
}
54+
55+
if (i == src.Length - 1)
56+
{
57+
return true;
58+
}
59+
60+
var l = src[i + 1];
61+
return l is < '\uDC00' or > '\uDFFF';
62+
}
3963

4064
public static string JsonEscape(this string contents)
4165
{
@@ -50,7 +74,8 @@ public static string JsonEscape(this string contents)
5074
}
5175

5276
builder.Append(contents, start, i - start);
53-
switch (contents[i])
77+
var content = contents[i];
78+
switch (content)
5479
{
5580
case '\b':
5681
builder.Append("\\b");
@@ -78,7 +103,7 @@ public static string JsonEscape(this string contents)
78103
break;
79104
default:
80105
builder.Append("\\u");
81-
builder.Append(((int) contents[i]).ToString("x04"));
106+
builder.Append(((int) content).ToString("x04"));
82107
break;
83108
}
84109

src/DiffEngineTray.Tests/DiffEngineTray.Tests.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<ItemGroup>
88
<Using Include="DiffEngine" />
99
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
10-
<PackageReference Include="Argon" Version="0.4.0" />
10+
<PackageReference Include="Argon" Version="0.5.0" />
1111
<PackageReference Include="Verify.DiffPlex" Version="2.2.0" />
1212
<PackageReference Include="Verify.WinForms" Version="4.0.0" />
1313
<PackageReference Include="Verify.Xunit" Version="19.10.0" />

0 commit comments

Comments
 (0)