Why isn't string assignment optimised when the length is known to the compiler?
问题 I was playing around today with some timing code and discovered that when asigning a string literal to std::string, that it was around 10% faster (with a short 12 char string, so likly even bigger difference for large strings) to do so with a literal of known length (using the sizeof operator) than not. (Only tested with the VC9 compiler, so I guess other compilers may do it better). std::string a("Hello World!"); std::string b("Hello World!", sizeof("Hello World!");//10% faster in my tests