xbmc/xbmc — pull request #3292 by bavison (2013-09-18 19:25:02+00:00)
Title: Faster string comparison functions in StringUtils

The methods EqualsNoCase(), StartsWith() and EndsWith() required quite a lot
of unncessary creation and destruction of std::strings, whether it be the
creation of a temporary copy that could be forced to lower-case, a temporary
copy that was a substring of one of the inputs, or just marshalling a
string literal argument into a std::string.

These functions don't appear to be used all that much at the moment; when I
profiled opening the songs library, I saw only a 1% improvement, which was
within the sampling noise threshold. But with PR #3225 and PR #3290 coming
along, that looks set to change. Once the functions are being called millions
of times, those heap operations really start to get noticeable.

One thing worth noting is that, for the sake of efficiency, when you compare
in a case-insentive manner against a string literal, it is assumed that the
string literal is already lower case. This patch includes changes to the few
places where such string literals use upper case characters to make them
conform. Unfortunately, there's an assumption that char *s are only used in
the case of string literals: that's true at present, but is a potential
gotcha for someone in the future.