Skip to content
This repository was archived by the owner on Dec 3, 2025. It is now read-only.

Commit 244bec2

Browse files
committed
Clear cached stack before use, and cleanup
1 parent 67a2792 commit 244bec2

7 files changed

Lines changed: 37 additions & 43 deletions

File tree

AL_Common/RTF/RtfDisplayedReadmeParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ private RtfError DispatchSpecialKeyword(SpecialType specialType, Symbol symbol,
195195
break;
196196
default:
197197
HandleSpecialTypeFont(_ctx, specialType, param);
198-
return RtfError.OK;
198+
break;
199199
}
200200

201201
return RtfError.OK;

AL_Common/RTF/RtfToTextConverter.cs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1859,7 +1859,7 @@ private RtfError DispatchSpecialKeyword(SpecialType specialType, Symbol symbol,
18591859
}
18601860
default:
18611861
HandleSpecialTypeFont(_ctx, specialType, param);
1862-
return RtfError.OK;
1862+
break;
18631863
}
18641864

18651865
return RtfError.OK;
@@ -2875,7 +2875,6 @@ private ListFast<char> GetCharFromCodePage(int codePage, uint codePoint)
28752875
{
28762876
_charGeneralBuffer.Count = GetEncodingFromCachedList(codePage)
28772877
.GetChars(_byteBuffer4, 0, 4, _charGeneralBuffer.ItemsArray, 0);
2878-
return _charGeneralBuffer;
28792878
}
28802879
else
28812880
{
@@ -2884,20 +2883,19 @@ private ListFast<char> GetCharFromCodePage(int codePage, uint codePoint)
28842883
{
28852884
_charGeneralBuffer.Count = enc
28862885
.GetChars(_byteBuffer4, 0, 4, _charGeneralBuffer.ItemsArray, 0);
2887-
return _charGeneralBuffer;
28882886
}
28892887
else
28902888
{
28912889
SetListFastToUnknownChar(_charGeneralBuffer);
2892-
return _charGeneralBuffer;
28932890
}
28942891
}
28952892
}
28962893
catch
28972894
{
28982895
SetListFastToUnknownChar(_charGeneralBuffer);
2899-
return _charGeneralBuffer;
29002896
}
2897+
2898+
return _charGeneralBuffer;
29012899
}
29022900

29032901
#endregion
@@ -2946,26 +2944,18 @@ private void PutChars_FieldInst(ListFast<char> ch, int count)
29462944
/// <param name="codePage"></param>
29472945
/// <returns></returns>
29482946
[MethodImpl(MethodImplOptions.AggressiveInlining)]
2949-
private Encoding GetEncodingFromCachedList(int codePage)
2947+
private Encoding GetEncodingFromCachedList(int codePage) => codePage switch
29502948
{
2951-
switch (codePage)
2952-
{
2953-
case _windows1252:
2954-
return _windows1252Encoding;
2955-
case 1250:
2956-
return _windows1250Encoding;
2957-
case 1251:
2958-
return _windows1251Encoding;
2959-
case _shiftJisWin:
2960-
return _shiftJisWinEncoding;
2961-
default:
2962-
return _encodings.TryGetValue(codePage, out Encoding result)
2963-
? result
2964-
// NOTE: This can throw, but all calls to this are wrapped in try-catch blocks.
2965-
// TODO: But weird that we don't put the try-catch here and just return null...?
2966-
: _encodings.AddAndReturn(codePage, Encoding.GetEncoding(codePage));
2967-
}
2968-
}
2949+
_windows1252 => _windows1252Encoding,
2950+
1250 => _windows1250Encoding,
2951+
1251 => _windows1251Encoding,
2952+
_shiftJisWin => _shiftJisWinEncoding,
2953+
_ => _encodings.TryGetValue(codePage, out Encoding result)
2954+
? result
2955+
// NOTE: This can throw, but all calls to this are wrapped in try-catch blocks.
2956+
// TODO: But weird that we don't put the try-catch here and just return null...?
2957+
: _encodings.AddAndReturn(codePage, Encoding.GetEncoding(codePage)),
2958+
};
29692959

29702960
[MethodImpl(MethodImplOptions.AggressiveInlining)]
29712961
private (bool Success, bool CodePageWas42, Encoding? Encoding, FontEntry? FontEntry)

AngelLoader/Filtering.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ internal static (FanMission? TitleExactMatch, FanMission? AuthorExactMatch)
400400

401401
if (ratingIsSet)
402402
{
403-
if ((fm.Rating < filterRatingFrom || fm.Rating > filterRatingTo))
403+
if (fm.Rating < filterRatingFrom || fm.Rating > filterRatingTo)
404404
{
405405
shownInFilter = false;
406406
}
@@ -414,11 +414,11 @@ internal static (FanMission? TitleExactMatch, FanMission? AuthorExactMatch)
414414

415415
if (releaseDateFilterSet)
416416
{
417-
if ((fm.ReleaseDate.DateTime == null ||
418-
(filterReleaseDateFrom != null &&
419-
fm.ReleaseDate.DateTime.Value.Date.CompareTo(filterReleaseDateFrom.Value.Date) < 0) ||
420-
(filterReleaseDateTo != null &&
421-
fm.ReleaseDate.DateTime.Value.Date.CompareTo(filterReleaseDateTo.Value.Date) > 0)))
417+
if (fm.ReleaseDate.DateTime == null ||
418+
(filterReleaseDateFrom != null &&
419+
fm.ReleaseDate.DateTime.Value.Date.CompareTo(filterReleaseDateFrom.Value.Date) < 0) ||
420+
(filterReleaseDateTo != null &&
421+
fm.ReleaseDate.DateTime.Value.Date.CompareTo(filterReleaseDateTo.Value.Date) > 0))
422422
{
423423
shownInFilter = false;
424424
}
@@ -432,11 +432,11 @@ internal static (FanMission? TitleExactMatch, FanMission? AuthorExactMatch)
432432

433433
if (lastPlayedFilterSet)
434434
{
435-
if ((fm.LastPlayed.DateTime == null ||
436-
(filterLastPlayedFrom != null &&
437-
fm.LastPlayed.DateTime.Value.Date.CompareTo(filterLastPlayedFrom.Value.Date) < 0) ||
438-
(filterLastPlayedTo != null &&
439-
fm.LastPlayed.DateTime.Value.Date.CompareTo(filterLastPlayedTo.Value.Date) > 0)))
435+
if (fm.LastPlayed.DateTime == null ||
436+
(filterLastPlayedFrom != null &&
437+
fm.LastPlayed.DateTime.Value.Date.CompareTo(filterLastPlayedFrom.Value.Date) < 0) ||
438+
(filterLastPlayedTo != null &&
439+
fm.LastPlayed.DateTime.Value.Date.CompareTo(filterLastPlayedTo.Value.Date) > 0))
440440
{
441441
shownInFilter = false;
442442
}
@@ -453,10 +453,10 @@ internal static (FanMission? TitleExactMatch, FanMission? AuthorExactMatch)
453453
uint fmFinished = fm.FinishedOn;
454454
bool fmFinishedOnUnknown = fm.FinishedOnUnknown;
455455

456-
if ((((fmFinished > 0 || fmFinishedOnUnknown) &&
457-
!viewFilter.Finished.HasFlagFast(FinishedState.Finished)) ||
458-
(fmFinished == 0 && !fmFinishedOnUnknown &&
459-
!viewFilter.Finished.HasFlagFast(FinishedState.Unfinished))))
456+
if (((fmFinished > 0 || fmFinishedOnUnknown) &&
457+
!viewFilter.Finished.HasFlagFast(FinishedState.Finished)) ||
458+
(fmFinished == 0 && !fmFinishedOnUnknown &&
459+
!viewFilter.Finished.HasFlagFast(FinishedState.Unfinished)))
460460
{
461461
shownInFilter = false;
462462
}

AngelLoader/Ini/IniCommon.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ private static bool SegmentEquals(this string first, int start, int end, string
578578
}
579579

580580
int secondLen = second.Length;
581-
if ((end - start) < secondLen - 1) return false;
581+
if (end - start < secondLen - 1) return false;
582582

583583
int i = start;
584584
int i2 = 0;

FMScanner/Scanner.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1137,9 +1137,11 @@ private void ScanFM(
11371137
? FMFormat.Rar
11381138
: FMFormat.NotInArchive;
11391139

1140+
// ReSharper disable ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
11401141
_archive?.Dispose();
11411142
_rarArchive?.Dispose();
11421143
_rarStream?.Dispose();
1144+
// ReSharper restore ConditionalAccessQualifierIsNonNullableAccordingToAPIContract
11431145

11441146
if (_fmFormat > FMFormat.NotInArchive)
11451147
{
@@ -5138,7 +5140,7 @@ ident string location into account.
51385140
*/
51395141

51405142
// Just check the bare ss2 fingerprinted value, because if we're here then we already know it's required
5141-
if ((_ss2Fingerprinted || SS2MisFilesPresent(_usedMisFiles, _ctx.FMFiles_SS2MisFiles)))
5143+
if (_ss2Fingerprinted || SS2MisFilesPresent(_usedMisFiles, _ctx.FMFiles_SS2MisFiles))
51425144
{
51435145
using Stream stream =
51445146
_solidGamFileToUse != null

FMScanner/ScannerUtility.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,8 @@ internal static string RemoveSurroundingParentheses(this string value, StackFast
335335
{
336336
if (value.IsEmpty() || value[0] != '(' || value[^1] != ')') return value;
337337

338+
stack.ClearFast();
339+
338340
ReadOnlySpan<char> valueSpan = value.AsSpan();
339341

340342
bool surroundedByParens = false;

FenGen/Utility/MiscUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,7 +461,7 @@ internal static string GetStringParamValue(AttributeSyntax attrSyntax, int argIn
461461
if (ins.Identifier.ToString() == "nameof")
462462
{
463463
SyntaxNode? argSyntax = ies.ChildNodes().FirstOrDefault(static x => x is ArgumentListSyntax);
464-
if (argSyntax is ArgumentListSyntax als && als.Arguments.Count == 1)
464+
if (argSyntax is ArgumentListSyntax { Arguments.Count: 1 } als)
465465
{
466466
return als.Arguments[0].Expression.ToString();
467467
}

0 commit comments

Comments
 (0)