src/hbcore/core/hbsharedcache.cpp
changeset 28 b7da29130b0e
parent 21 4633027730f5
equal deleted inserted replaced
23:e6ad4ef83b23 28:b7da29130b0e
    23 **
    23 **
    24 ****************************************************************************/
    24 ****************************************************************************/
    25 
    25 
    26 #include "hbsharedcache_p.h"
    26 #include "hbsharedcache_p.h"
    27 #include "hbsharedmemorymanager_p.h"
    27 #include "hbsharedmemorymanager_p.h"
       
    28 #include "hbhash_p.h"
    28 #ifdef HB_BIN_CSS
    29 #ifdef HB_BIN_CSS
    29 #include "hbcssconverterutils_p.h"
    30 #include "hbcssconverterutils_p.h"
    30 #endif
    31 #endif
    31 #include <QSystemSemaphore>
    32 #include <QSystemSemaphore>
    32 
    33 
    65     HbSharedCache *ptr = 0;
    66     HbSharedCache *ptr = 0;
    66     if (manager) {
    67     if (manager) {
    67         ptr = static_cast<HbSharedMemoryManager*>(manager)->cache();
    68         ptr = static_cast<HbSharedMemoryManager*>(manager)->cache();
    68     }
    69     }
    69     return ptr;
    70     return ptr;
    70 }
       
    71 
       
    72 /*!
       
    73     return hash value for \a string.
       
    74 */
       
    75 quint32 HbSharedCache::hash(const QStringRef &string)
       
    76 {
       
    77     quint32 hashValue = 0;
       
    78     const QChar *data = string.unicode();
       
    79     int size = string.size();
       
    80     while (size--) {
       
    81         hashValue = data->unicode() + (hashValue << 6) + (hashValue << 16) - hashValue;
       
    82         ++data;
       
    83     }
       
    84     return hashValue;
       
    85 }
    71 }
    86 
    72 
    87 /*!
    73 /*!
    88     adds \a offset using key \a key. \a itemType is the type of the structure,
    74     adds \a offset using key \a key. \a itemType is the type of the structure,
    89     where offset points to.
    75     where offset points to.
   152     }
   138     }
   153     if (mOffsetItemCount > 0) {
   139     if (mOffsetItemCount > 0) {
   154         //try first in prebuilt offset map.
   140         //try first in prebuilt offset map.
   155         length -= WidgetMLFileExtension.length();
   141         length -= WidgetMLFileExtension.length();
   156         QStringRef widgetname(&filePath, position, length);
   142         QStringRef widgetname(&filePath, position, length);
   157         HbOffsetItem find(hash(widgetname));
   143         HbOffsetItem find(hbHash(widgetname));
   158         const HbOffsetItem *end = mOffsetItems + mOffsetItemCount;
   144         const HbOffsetItem *end = mOffsetItems + mOffsetItemCount;
   159         const HbOffsetItem *offsetItem = qBinaryFind(mOffsetItems, end, find);
   145         const HbOffsetItem *offsetItem = qBinaryFind(mOffsetItems, end, find);
   160         if (offsetItem != end) {
   146         if (offsetItem != end) {
   161 #ifdef CSSBIN_TRACES
   147             THEME_CSSBIN_DEBUG() << "Offset item found from static cache map for widget: " << widgetname;
   162             qDebug() << "Offset item found from static cache map for widget: " << widgetname;
       
   163 #endif
       
   164             qint32 tableSize = 0;
   148             qint32 tableSize = 0;
   165             const HbLayoutIndexItem *begin = layoutIndexItemBegin(
   149             const HbLayoutIndexItem *begin = layoutIndexItemBegin(
   166                     offsetItem->offsetLayoutIndexTable, &tableSize);
   150                     offsetItem->offsetLayoutIndexTable, &tableSize);
   167             if (begin) {
   151             if (begin) {
   168                 const HbLayoutIndexItem *end = begin + tableSize;
   152                 const HbLayoutIndexItem *end = begin + tableSize;
   169                 HbLayoutIndexItem find(hash(QStringRef(&layout)), hash(QStringRef(&section)));
   153                 HbLayoutIndexItem find(hbHash(QStringRef(&layout)), hbHash(QStringRef(&section)));
   170                 const HbLayoutIndexItem *item = qBinaryFind(begin, end, find);
   154                 const HbLayoutIndexItem *item = qBinaryFind(begin, end, find);
   171                 if (item != end) {
   155                 if (item != end) {
   172 #ifdef CSSBIN_TRACES
   156                     THEME_CSSBIN_DEBUG() << "Layout definition offset found for layout: " << layout;
   173                     qDebug() << "Layout definition offset found for layout: " << layout;
       
   174 #endif
       
   175                     offset = item->offset;
   157                     offset = item->offset;
   176                 }
   158                 }
   177             }
   159             }
   178         }
   160         }
   179     }
   161     }
   219             isColorCSS = true;
   201             isColorCSS = true;
   220         } else {
   202         } else {
   221             length -= CSSFileExtension.length();
   203             length -= CSSFileExtension.length();
   222         }
   204         }
   223         QStringRef widgetname(&key, position, length);
   205         QStringRef widgetname(&key, position, length);
   224         HbOffsetItem find(hash(widgetname));
   206         HbOffsetItem find(hbHash(widgetname));
   225         const HbOffsetItem *end = mOffsetItems + mOffsetItemCount;
   207         const HbOffsetItem *end = mOffsetItems + mOffsetItemCount;
   226         const HbOffsetItem *offsetItem = qBinaryFind(mOffsetItems, end, find);
   208         const HbOffsetItem *offsetItem = qBinaryFind(mOffsetItems, end, find);
   227         if (offsetItem != end) {
   209         if (offsetItem != end) {
   228 #ifdef CSSBIN_TRACES
   210             THEME_CSSBIN_DEBUG() << "Offset item found from static cache map for widget: " << widgetname;
   229             qDebug() << "Offset item found from static cache map for widget: " << widgetname;
       
   230 #endif
       
   231             offset = (isColorCSS) ? offsetItem->offsetColorCSS : offsetItem->offsetCSS;
   211             offset = (isColorCSS) ? offsetItem->offsetColorCSS : offsetItem->offsetCSS;
   232         }
   212         }
   233     }
   213     }
   234     if (offset == -1) {
   214     if (offset == -1) {
   235         QStringRef keyRef(&key, position, key.length() - position);
   215         QStringRef keyRef(&key, position, key.length() - position);
   403 {
   383 {
   404     mEffectCache.reserve(20);
   384     mEffectCache.reserve(20);
   405 
   385 
   406     //server creates the semaphore.
   386     //server creates the semaphore.
   407     Semaphore = new QSystemSemaphore(SemaphoreName, 1, QSystemSemaphore::Create);
   387     Semaphore = new QSystemSemaphore(SemaphoreName, 1, QSystemSemaphore::Create);
   408 #ifdef CSSBIN_TRACES
   388     THEME_CSSBIN_DEBUG() << "css offset items total: " << mOffsetItemCount;
   409     qDebug() << "css offset items total: " << mOffsetItemCount;
       
   410 #endif
       
   411 }
   389 }
   412 
   390 
   413 /*!
   391 /*!
   414     client side initialization function.
   392     client side initialization function.
   415 */
   393 */