Skip to content

Commit 23658bd

Browse files
Fixed large enum lookup.
1 parent e981f56 commit 23658bd

3 files changed

Lines changed: 10 additions & 9 deletions

File tree

Source/EnumValue.cs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ internal static Func<string, ValueLookupResult> ValueLookup
172172

173173
var result = new Entry[]?[longest + 1];
174174
foreach (var i in d.Keys)
175-
result[i] = d[i].OrderBy(v=>v.Name).ToArray();
175+
result[i] = d[i].OrderBy(v => v.Name).ToArray();
176176

177177
return result;
178178
}
@@ -188,7 +188,7 @@ public Entry(string name, TEnum value)
188188
public string Name { get; }
189189
public TEnum Value { get; }
190190

191-
public void Deconstruct(out string name, out TEnum value)
191+
public void Deconstruct(out string name, out TEnum value)
192192
{
193193
name = Name;
194194
value = Value;
@@ -198,9 +198,9 @@ public static int Find(Span<Entry> span, ReadOnlySpan<char> name, StringComparis
198198
{
199199
// Small enough? Just brute force the index.
200200
var len = span.Length;
201-
if(len < 12)
201+
if (len < 12)
202202
{
203-
for(var i = 0; i< len; i++)
203+
for (var i = 0; i < len; i++)
204204
{
205205
ref Entry e = ref span[i];
206206
if (name.Equals(e.Name, sc))
@@ -224,13 +224,14 @@ public static int Find(Span<Entry> span, ReadOnlySpan<char> name, StringComparis
224224

225225
var comparison = name.CompareTo(middleKey, sc);
226226
if (comparison < 0)
227-
left = middle + 1;
228-
else if (comparison > 0)
229227
right = middle - 1;
228+
else if (comparison > 0)
229+
left = middle + 1;
230230
else
231231
return middle;
232232
}
233233

234+
234235
return -1;
235236
}
236237
}
@@ -558,7 +559,7 @@ public static bool TryParse<TEnum>(StringSegment name, bool ignoreCase, out TEnu
558559

559560
var span = r.AsSpan();
560561
var index = EnumValue<TEnum>.Entry.Find(span, name, sc);
561-
if(index != -1)
562+
if (index != -1)
562563
{
563564
e = span[index].Value;
564565
return true;

Source/Open.Text.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<RepositoryUrl>https://github.com/Open-NET-Libraries/Open.Text</RepositoryUrl>
2020
<RepositoryType>git</RepositoryType>
2121
<PackageTags>string, span, enum, readonlyspan, text, format, split, trim, equals, trimmed equals, first, last, preceding, following, stringbuilder, extensions, stringcomparable, spancomparable, stringsegment, splitassegment</PackageTags>
22-
<Version>6.6.1</Version>
22+
<Version>6.6.2</Version>
2323
<PackageReleaseNotes></PackageReleaseNotes>
2424
<PackageLicenseExpression>MIT</PackageLicenseExpression>
2525
<PublishRepositoryUrl>true</PublishRepositoryUrl>

Tests/EnumValueTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,5 +270,5 @@ public static void LongEnumTests()
270270

271271
[Fact]
272272
public static void LargeEnumTests()
273-
=> TryParseTestsCore<LargeEnum>();
273+
=> TryParseTestsCore<LargeEnum>();
274274
}

0 commit comments

Comments
 (0)