Skip to content

Commit

Permalink
Lucene.Net.Util.OfflineSorter: Removed unnecessary calls to ElementAt…
Browse files Browse the repository at this point in the history
…() and Count() LINQ methods, fixed boxing issue with the Assert.AreEquals call when comparing files (addresses #295).
  • Loading branch information
NightOwl888 committed Jun 24, 2020
1 parent 423bf3a commit 2dd70a1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 21 deletions.
29 changes: 12 additions & 17 deletions src/Lucene.Net.Tests/Util/TestOfflineSorter.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using J2N.Text;
using Lucene.Net.Attributes;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.IO;
using NUnit.Framework;
using Lucene.Net.Attributes;
using J2N.Text;
using Assert = Lucene.Net.TestFramework.Assert;

namespace Lucene.Net.Util
Expand Down Expand Up @@ -157,23 +157,18 @@ private void AssertFilesIdentical(FileInfo golden, FileInfo sorted)
byte[] buf1 = new byte[64 * 1024];
byte[] buf2 = new byte[64 * 1024];
int len;
//DataInputStream is1 = new DataInputStream(new FileInputStream(golden));
//DataInputStream is2 = new DataInputStream(new FileInputStream(sorted));
using (Stream is1 = golden.Open(FileMode.Open, FileAccess.Read, FileShare.Delete))
using (Stream is2 = sorted.Open(FileMode.Open, FileAccess.Read, FileShare.Delete))
{
using (Stream is2 = sorted.Open(FileMode.Open, FileAccess.Read, FileShare.Delete))
while ((len = is1.Read(buf1, 0, buf1.Length)) > 0)
{
while ((len = is1.Read(buf1, 0, buf1.Length)) > 0)
{
is2.Read(buf2, 0, len);
// Refactored test to let NUnit test the byte array rather than iterate each byte
//for (int i = 0; i < len; i++)
//{
// Assert.AreEqual(buf1[i], buf2[i]);
//}
Assert.AreEqual(buf1, buf2);
}
//IOUtils.Close(is1, is2);
is2.Read(buf2, 0, len);
// Refactored test to let NUnit test the byte array rather than iterate each byte
//for (int i = 0; i < len; i++)
//{
// Assert.AreEqual(buf1[i], buf2[i]);
//}
Assert.AreEqual(buf1, buf2);
}
}
}
Expand Down
7 changes: 3 additions & 4 deletions src/Lucene.Net/Util/OfflineSorter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Text;

namespace Lucene.Net.Util
Expand Down Expand Up @@ -396,13 +395,13 @@ internal void MergePartitions(IList<FileInfo> merges, FileInfo outputFile)

var @out = new ByteSequencesWriter(outputFile);

PriorityQueue<FileAndTop> queue = new PriorityQueueAnonymousInnerClassHelper(this, merges.Count());
PriorityQueue<FileAndTop> queue = new PriorityQueueAnonymousInnerClassHelper(this, merges.Count);

var streams = new ByteSequencesReader[merges.Count()];
var streams = new ByteSequencesReader[merges.Count];
try
{
// Open streams and read the top for each file
for (int i = 0; i < merges.Count(); i++)
for (int i = 0; i < merges.Count; i++)
{
streams[i] = new ByteSequencesReader(merges[i]);
byte[] line = streams[i].Read();
Expand Down

0 comments on commit 2dd70a1

Please sign in to comment.