Ticket #10449: 10449-elfhash2.patch

File 10449-elfhash2.patch, 1.8 KB (added by stuartm, 12 years ago)

Updated patch - use this instead

  • mythtv/programs/mythfilldatabase/xmltvparser.cpp

    commit 754aa07571271a7f01400d8957477858260ca51a
    Author: Stuart Morgan <smorgan@mythtv.org>
    Date:   Wed Mar 14 21:32:14 2012 +0000
    
        Use the same version of ELFHash as QT does in qlinguist/qrelease, this version involves fewer casts and less chance of losing data in the process.
    
    diff --git a/mythtv/programs/mythfilldatabase/xmltvparser.cpp b/mythtv/programs/mythfilldatabase/xmltvparser.cpp
    index 8b5b562..20230d2 100644
    a b XMLTVParser::XMLTVParser() : isJapan(false), current_year(0) 
    3030    current_year = QDate::currentDate().toString("yyyy").toUInt();
    3131}
    3232
    33 static unsigned int ELFHash(const char *s)
     33static uint ELFHash(const QByteArray &ba)
    3434{
    35     /* ELF hash uses unsigned chars and unsigned arithmetic for portability */
    36     const unsigned char *name = (const unsigned char *)s;
    37     unsigned long h = 0, g;
     35    const uchar *k = (const uchar *)ba.data();
     36    uint h = 0;
     37    uint g;
    3838
    39     while (*name)
     39    if (k)
    4040    {
    41         h = (h << 4) + (unsigned long)(*name++);
    42         if ((g = (h & 0xF0000000UL))!=0)
    43             h ^= (g >> 24);
    44         h &= ~g;
    45 
     41        while (*k)
     42        {
     43            h = (h << 4) + *k++;
     44            if ((g = (h & 0xf0000000)) != 0)
     45                h ^= g >> 24;
     46            h &= ~g;
     47        }
    4648    }
    4749
    48     return (int)h;
     50    return h;
    4951}
    5052
    5153static QString getFirstText(QDomElement element)
    ProgInfo *XMLTVParser::parseProgram( 
    533535        programid.append(uniqueid);
    534536    else
    535537    {
    536         QString seriesid = QString::number(ELFHash(pginfo->title.toLocal8Bit()
    537                                                .constData()));
     538        QString seriesid = QString::number(ELFHash(pginfo->title.toUtf8()));
    538539        pginfo->seriesId = seriesid;
    539540        programid.append(seriesid);
    540541