Skip to content

Commit

Permalink
Small compaction
Browse files Browse the repository at this point in the history
  • Loading branch information
FenPhoenix committed Aug 28, 2023
1 parent b7f4f4b commit ec14e0a
Showing 1 changed file with 10 additions and 30 deletions.
40 changes: 10 additions & 30 deletions FMScanner/Core/Scanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2407,19 +2407,8 @@ static bool BaseDirScriptFileExtensions(List<NameAndIndex> baseDirFiles, string[

if (missFlagIndex > -1)
{
NameAndIndex missFlag = _stringsDirFiles[missFlagIndex];
List<string> mfLines;

// missflag.str files are always ASCII / UTF8, so we can avoid an expensive encoding detect here
if (_fmFormat == FMFormat.Zip)
{
using var es = _archive.OpenEntry(_archive.Entries[missFlag.Index]);
mfLines = ReadAllLines(es, Encoding.UTF8);
}
else
{
mfLines = ReadAllLines(Path.Combine(_fmWorkingPath, missFlag.Name), Encoding.UTF8);
}
List<string> mfLines = ReadAllLinesUTF8(_stringsDirFiles[missFlagIndex]);

for (int mfI = 0; mfI < _misFiles.Count; mfI++)
{
Expand Down Expand Up @@ -4619,7 +4608,7 @@ private string[] EnumFiles(string path, SearchOption searchOption)

#region Read plaintext

#region ReadAllText (detect encoding)
#region Read all text

/// <summary>
/// Reads all the text in a stream, auto-detecting its encoding. Ensures non-ASCII characters show up
Expand All @@ -4637,10 +4626,6 @@ private string ReadAllTextE(Stream stream)
return sr.Reader.ReadToEnd();
}

#endregion

#region ReadAllText (as is)

private string ReadAllText(Stream stream, Encoding encoding)
{
using var sr = new StreamReaderCustom.SRC_Wrapper(stream, encoding, true, _streamReaderCustom, disposeStream: false);
Expand All @@ -4649,7 +4634,7 @@ private string ReadAllText(Stream stream, Encoding encoding)

#endregion

#region ReadAllLines (detect encoding)
#region Read all lines (detect encoding)

/// <summary>
/// Reads all the lines in a stream, auto-detecting its encoding. Ensures non-ASCII characters show up
Expand Down Expand Up @@ -4698,23 +4683,18 @@ private List<string> ReadAllLinesE(string file)

#endregion

#region ReadAllLines (as is)
#region Read all lines (as is)

private List<string> ReadAllLines(Stream stream, Encoding encoding)
private List<string> ReadAllLinesUTF8(NameAndIndex item)
{
var lines = new List<string>();

using var sr = new StreamReaderCustom.SRC_Wrapper(stream, encoding, false, _streamReaderCustom);
while (sr.Reader.ReadLine() is { } line) lines.Add(line);

return lines;
}

private List<string> ReadAllLines(string file, Encoding encoding)
{
var lines = new List<string>();
using Stream stream = _fmFormat == FMFormat.Zip
? _archive.OpenEntry(_archive.Entries[item.Index])
: GetReadModeFileStreamWithCachedBuffer(Path.Combine(_fmWorkingPath, item.Name), DiskFileStreamBuffer);

using var sr = new StreamReaderCustom.SRC_Wrapper(GetReadModeFileStreamWithCachedBuffer(file, DiskFileStreamBuffer), encoding, false, _streamReaderCustom);
// Stupid micro-optimization: Don't call Dispose() method on stream twice
using var sr = new StreamReaderCustom.SRC_Wrapper(stream, Encoding.UTF8, false, _streamReaderCustom, disposeStream: false);
while (sr.Reader.ReadLine() is { } line) lines.Add(line);

return lines;
Expand Down

0 comments on commit ec14e0a

Please sign in to comment.