title: Slowdown with recursive function using vectors
body: <p>I'm running this function around 30 times per frame and experiencing massive slow down. This function is the cause of it, any ideas why?</p>
  
  <pre><code>bool Pathfinding::takeStep(
      std::vector&lt;std::vector&lt;int&gt;&gt;* vec, int px, int py, int sx, int sy, int r)
  {
      if (px == sx &amp;&amp; py == sy) return true;  // destination reached
      bool clear = true;
      // step up
      if ((*vec)[px][py - 1] == -1)  // location not tested yet
      {
          for (int i = 0; i &lt; r * 2; ++i)
          {
              int tx = px - r + i;
              int ty = py - r - 1;
              // Make sure test coordinates are on the grid
              if (tx &gt; 0 &amp;&amp; ty &gt; 0 &amp;&amp; tx &lt; width &amp;&amp; ty &lt; height)
              {
                  // already stuck
                  if (grid[tx][ty] == 1) clear = false;
              }
              else
                  clear = false;  // not on grid
          }
          if (clear)
          {
              // keep moving
              (*vec)[px][py - 1] = (*vec)[px][py] + 1;
              // add one to step count and confirm this way is clear
              if (takeStep(vec, px, py - 1, sx, sy, r)) return true;
          }
          else
          {
              (*vec)[px][py - 1] = -2;  // mark as already tried
          }
      }
      return false;
  }
  </code></pre>