title: std::string _M_leak_hard and performance concerns
body: <p>While profiling a C++ application, I've noticed that the following code:</p>
  
  <pre><code>std::string s;
  int i;
  
  dict[s[i]] ++; 
  </code></pre>
  
  <p>yields an invokation of (inline) <code>std::string::_M_leak_hard</code>, chaining into <code>std::string::_M_mutate</code> and more (gcc-4.7.3), and going through an insane number of CPU instructions comparing internal state of string, at what should've been a const context and optimized away to a simple memory read. </p>
  
  <p>Am I doing something terribly wrong? That chain of std::string implementation-specific detail burns easily through 50% of the CPU time. </p>