Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>What is the <code>_Bytes(I)</code> call doing? It's not loading the file each time, is it? Even with buffering, that would be bad news!</p> <p>There will be plenty of ways to <em>micro-optimise</em> this in terms of looking at longs at a time, potentially using unsafe code etc - but I'd just concentrate on getting <em>reasonable</em> performance first. Clearly there's something very odd going on.</p> <p>I suggest you extract the comparison code into a separate function which takes two byte arrays. That way you know you won't be doing anything odd. I'd also use a simple <code>For</code> loop rather than <code>For Each</code> in this case - it'll be simpler. Oh, and check whether the lengths are correct first :)</p> <p>EDIT: Here's the code (untested, but simple enough) that I'd use. It's in C# for the minute - I'll convert it in a sec:</p> <pre><code>public static bool Equals(byte[] first, byte[] second) { if (first == second) { return true; } if (first == null || second == null) { return false; } if (first.Length != second.Length) { return false; } for (int i=0; i &lt; first.Length; i++) { if (first[i] != second[i]) { return false; } } return true; } </code></pre> <p>EDIT: And here's the VB:</p> <pre><code>Public Shared Function ArraysEqual(ByVal first As Byte(), _ ByVal second As Byte()) As Boolean If (first Is second) Then Return True End If If (first Is Nothing OrElse second Is Nothing) Then Return False End If If (first.Length &lt;&gt; second.Length) Then Return False End If For i as Integer = 0 To first.Length - 1 If (first(i) &lt;&gt; second(i)) Then Return False End If Next i Return True End Function </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload