Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Its possible that traversing the array in reverse-order is doing this: from what I know, arrays are optimized for forward/sequential access. Furthermore you might be preventing the JIT from doing bounds-checking elimination with all that arithmetic. Try this:</p> <pre><code> for (int i = cut; i &lt; blockArray.Length; i++) { if (!StringComparer.Ordinal.Equals(blockArray[i], container[i])) return false; } </code></pre> <p>However, in the end it depends on how many items you have in the array - if there are a lot there isn't much you can do (except use unsafe code, but that is only going to give you a tiny bit extra).</p> <p><strong>Edit:</strong> you can improve the speed of negative cases using HashCodes; at the cost of memory.</p> <pre><code>class StringAndHash { public int HashCode; public string Value; public StringAndHash(string value) { if (value == null) HashCode = 0; else HashCode = StringComparer.Ordinal.GetHashCode(value.GetHashCode()); Value = value; } public static implicit operator string(StringAndHash value) { return value.Value; } public static implicit operator StringAndHash(string value) { return new StringAndHash(value); } public override int GetHashCode() { return HashCode; } public override bool Equals(object obj) { var sah = obj as StringAndHash; if (!object.ReferenceEquals(sah, null)) { return Equals(sah); } return base.Equals(obj); } public override bool Equals(StringAndHash obj) { return obj.HashCode == HashCode // This will improve perf in negative cases. &amp;&amp; StringComparer.Ordinal.Equals(obj.Value, Value); } } public Dictionary&lt;string, StringAndHash[]&gt; blockProperty; bool BlockMatch(IList&lt;StringAndHash&gt; container, string block, int cut) { var blockArray = blockProperty[block]; var length = blockArray.Length - cut; if (length &gt; container.Count) { return false; } for (int i = cut; i &lt; blockArray.Length; i++) { if (blockArray[i].Equals(container[i])) { return false; } } return true; } </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