Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are a couple things to consider in there. First, just so you know the right terminology, this is actually unboxing (you've taken a value-type and stored it as a reference-type, or boxed it. Reverting to the value-type is unboxing).</p> <p>Second, I'd wager that the majority of your code isn't in the unboxing, instead it's in the multiple calls into the cache dictionary:</p> <pre><code>if (cast_cache.ContainsKey(id) &amp;&amp; cast_cache[id].ContainsKey(key)) return (int)cast_cache[id][key] </code></pre> <p>I count 5 dictionary traverses in there: cast_cache.ContainsKey(id), cast_cache[id], .ContainstKey(key), cast_cache[id], and [key]. </p> <p>That's pretty harsh. You could cut down on a lot of these by using an aggregated key. Instead of looking for [id][key], combine those into a single object. That would cut your number of dictionaries down exponentially and cut those lookups down to 2, 1 if you skip the ContainsKey() with a try/catch (check the speed on that).</p> <p>Here's a class that would allow you to combine those:</p> <pre><code>public class Vector { private object[] _Data; public object this[int index] { get { return _Data[index]; } } public Vector(params object[] data) { _Data = (object[])data.Clone(); } public override bool Equals(object obj) { Vector OtherVector = obj as Vector; if (OtherVector == null) return false; if (OtherVector._Data.Length != _Data.Length) return false; for (int I = 0; I &lt; _Data.Length; I++) if (!_Data[I].Equals(OtherVector._Data[I])) return false; return true; } public override int GetHashCode() { int Result = 0; for (int I = 0; I &lt; _Data.Length; I++) Result = Result ^ (_Data[I].GetHashCode() * I); return Result; } } </code></pre> <p>Try that out and see how your speed goes</p>
 

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