xbmc/xbmc — pull request #3709 by bavison (2013-11-25 19:05:43+00:00)
Title: Add caching of text labels at the UTF8 level

Previously, CGUITextLayout::Update converted its string argument from UTF8 to
UTF16, then passed it to CGUITextLayout::UpdateW, where it was compared
against a cached copy of the string (in its UTF16 form). However, the
conversion itself was taking up a reasonable chunk of CPU time.

This patch adds a similar cache of the string in its UTF8 form to the Update
method, and splits the non-cache part of UpdateW into a separate function, so
we can bypass it the case where we've tested it against the UTF8 cache.

I have also changed the string comparison to be case-sensitive; it seems
likely that it was only case-insensitive due to the the default seting of
CStdStr::Equals. It's unlikely that you'd ever want to update a string with
another which is the same except for the case of one or more characters, but
if you did, I doubt you'd want to use the cached version if so. And you're
slowing down the comparison in all other cases to achieve that dubious
behaviour.

I have measured the effect while the Videos window of the default skin was
open (but idle) on a Raspberry Pi, and this reduced the CPU usage by 2.9%
from 39.1% to 36.2%:

Before After
Mean StdDev Mean StdDev Confidence Change
IdleCPU% 39.1 0.9 36.2 0.5 100.0% +8.1%