Convert part of loop into LINQ.

This commit is contained in:
2021-08-17 17:51:01 +01:00
parent 00ee79bc69
commit f757716c2c
8 changed files with 30 additions and 61 deletions

View File

@@ -1647,32 +1647,27 @@ namespace Aaru.Devices.Remote
int off = tmp.Length;
foreach(Device.MmcSingleCommand command in commands)
foreach(AaruCmdSdhci cmd in commands.Select(command => new AaruCmdSdhci
{
application = command.isApplication,
argument = command.argument,
block_size = command.blockSize,
blocks = command.blocks,
buf_len = (uint)(command.buffer?.Length ?? 0),
command = command.command,
flags = command.flags,
timeout = timeout,
write = command.write
}))
{
var cmd = new AaruCmdSdhci
{
application = command.isApplication,
argument = command.argument,
block_size = command.blockSize,
blocks = command.blocks,
buf_len = (uint)(command.buffer?.Length ?? 0),
command = command.command,
flags = command.flags,
timeout = timeout,
write = command.write
};
tmp = Marshal.StructureToByteArrayLittleEndian(cmd);
Array.Copy(tmp, 0, buf, off, tmp.Length);
off += tmp.Length;
}
foreach(Device.MmcSingleCommand command in commands)
foreach(Device.MmcSingleCommand command in commands.Where(command => (command.buffer?.Length ?? 0) != 0))
{
if((command.buffer?.Length ?? 0) == 0)
continue;
Array.Copy(command.buffer, 0, buf, off, command.buffer.Length);
off += command.buffer.Length;

View File

@@ -31,6 +31,7 @@
// ****************************************************************************/
using System;
using System.Linq;
using System.Text;
using Aaru.CommonTypes;
using Aaru.CommonTypes.Interfaces;
@@ -61,11 +62,8 @@ namespace Aaru.Filesystems
foreach(int offset in new[]
{
0, 0x200, 0x400, 0x600, 0x800, 0xA00
})
}.Where(offset => mdbSector.Length >= offset + 0x7C + 2))
{
if(mdbSector.Length < offset + 0x7C + 2)
continue;
drSigWord = BigEndianBitConverter.ToUInt16(mdbSector, offset);
if(drSigWord != AppleCommon.HFS_MAGIC)

View File

@@ -1218,11 +1218,8 @@ namespace Aaru.DiscImages
{
var lastTrackInSession = new Track();
foreach(Track trk in Tracks.Where(trk => trk.TrackSession == leadOuts.Key))
{
if(trk.TrackSequence > lastTrackInSession.TrackSequence)
lastTrackInSession = trk;
}
foreach(Track trk in Tracks.Where(trk => trk.TrackSession == leadOuts.Key).Where(trk => trk.TrackSequence > lastTrackInSession.TrackSequence))
lastTrackInSession = trk;
if(lastTrackInSession.TrackSequence == 0 ||
lastTrackInSession.TrackEndSector == (ulong)leadOuts.Value - 1)

View File

@@ -1388,11 +1388,8 @@ namespace Aaru.DiscImages
{
var lastTrackInSession = new Track();
foreach(Track trk in Tracks.Where(trk => trk.TrackSession == leadOuts.Key))
{
if(trk.TrackSequence > lastTrackInSession.TrackSequence)
lastTrackInSession = trk;
}
foreach(Track trk in Tracks.Where(trk => trk.TrackSession == leadOuts.Key).Where(trk => trk.TrackSequence > lastTrackInSession.TrackSequence))
lastTrackInSession = trk;
if(lastTrackInSession.TrackSequence == 0 ||
lastTrackInSession.TrackEndSector == (ulong)leadOuts.Value - 1)

View File

@@ -77,22 +77,12 @@ namespace Aaru.DiscImages
// Detect ProDOS skewed disks
if(skewed)
foreach(Apple2.RawSector sector in tracks[17].sectors)
foreach(bool isDos in from sector in tracks[17].sectors where sector.addressField.sector.SequenceEqual(new byte[]
{
170, 170
}) select Apple2.DecodeSector(sector) into sector0 where sector0 != null select sector0[0x01] == 17 && sector0[0x02] < 16 && sector0[0x27] <= 122 &&
sector0[0x34] == 35 && sector0[0x35] == 16 && sector0[0x36] == 0 && sector0[0x37] == 1)
{
if(!sector.addressField.sector.SequenceEqual(new byte[]
{
170, 170
}))
continue;
byte[] sector0 = Apple2.DecodeSector(sector);
if(sector0 == null)
continue;
bool isDos = sector0[0x01] == 17 && sector0[0x02] < 16 && sector0[0x27] <= 122 &&
sector0[0x34] == 35 && sector0[0x35] == 16 && sector0[0x36] == 0 && sector0[0x37] == 1;
if(isDos)
skewing = _dosSkewing;

View File

@@ -60,9 +60,8 @@ namespace Aaru.DiscImages
{
var ctx = new Sha1Context();
foreach(IFilter filter in filters)
foreach(Stream stream in filters.Select(filter => filter.GetDataForkStream()))
{
Stream stream = filter.GetDataForkStream();
readBytes = 0;
verifyBytes = new byte[verifySize];
@@ -89,9 +88,8 @@ namespace Aaru.DiscImages
{
var ctx = new Md5Context();
foreach(IFilter filter in filters)
foreach(Stream stream in filters.Select(filter => filter.GetDataForkStream()))
{
Stream stream = filter.GetDataForkStream();
readBytes = 0;
verifyBytes = new byte[verifySize];
@@ -118,9 +116,8 @@ namespace Aaru.DiscImages
{
var ctx = new Crc32Context();
foreach(IFilter filter in filters)
foreach(Stream stream in filters.Select(filter => filter.GetDataForkStream()))
{
Stream stream = filter.GetDataForkStream();
readBytes = 0;
verifyBytes = new byte[verifySize];

View File

@@ -613,14 +613,9 @@ namespace Aaru.DiscImages
if(trackIndexes.TryGetValue((byte)tmpTrack.TrackSequence, out Dictionary<byte, int> indexes))
{
foreach(KeyValuePair<byte, int> trackIndex in indexes.OrderBy(i => i.Key))
{
if(trackIndex.Key <= 1)
continue;
foreach((byte index, int value) in indexes.OrderBy(i => i.Key).Where(trackIndex => trackIndex.Key > 1))
// Untested as of 20210711
tmpTrack.Indexes[trackIndex.Key] = trackIndex.Value;
}
tmpTrack.Indexes[index] = value;
}
if(tmpTrack.TrackType == TrackType.Data)