Skip to content

Commit

Permalink
Use the same version of ELFHash as QT does in qlinguist/qrelease, thi…
Browse files Browse the repository at this point in the history
…s version involves fewer casts and less chance of losing data in the process.
  • Loading branch information
stuartm committed May 11, 2012
1 parent da86aeb commit fe8e17d
Showing 1 changed file with 14 additions and 13 deletions.
27 changes: 14 additions & 13 deletions mythtv/programs/mythfilldatabase/xmltvparser.cpp
Expand Up @@ -30,22 +30,24 @@ XMLTVParser::XMLTVParser() : isJapan(false), current_year(0)
current_year = QDate::currentDate().toString("yyyy").toUInt();
}

static unsigned int ELFHash(const char *s)
static uint ELFHash(const QByteArray &ba)
{
/* ELF hash uses unsigned chars and unsigned arithmetic for portability */
const unsigned char *name = (const unsigned char *)s;
unsigned long h = 0, g;
const uchar *k = (const uchar *)ba.data();
uint h = 0;
uint g;

while (*name)
if (k)
{
h = (h << 4) + (unsigned long)(*name++);
if ((g = (h & 0xF0000000UL))!=0)
h ^= (g >> 24);
h &= ~g;

while (*k)
{
h = (h << 4) + *k++;
if ((g = (h & 0xf0000000)) != 0)
h ^= g >> 24;
h &= ~g;
}
}

return (int)h;
return h;
}

static QString getFirstText(QDomElement element)
Expand Down Expand Up @@ -533,8 +535,7 @@ ProgInfo *XMLTVParser::parseProgram(
programid.append(uniqueid);
else
{
QString seriesid = QString::number(ELFHash(pginfo->title.toUtf8()
.constData()));
QString seriesid = QString::number(ELFHash(pginfo->title.toUtf8()));
pginfo->seriesId = seriesid;
programid.append(seriesid);

Expand Down

0 comments on commit fe8e17d

Please sign in to comment.