Alien-SmokeQt

 view release on metacpan or  search on metacpan

generator/parser/indexedstring.cpp  view on Meta::CPAN

/***************************************************************************
   Copyright 2008 David Nolden <david.nolden.kdevelop@art-master.de>
***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#include <QtCore/QStringList>
#include <QtCore/QUrl>
#include <QtDebug>

#include "indexedstring.h"
// #include "repositories/stringrepository.h"

// #include "referencecounting.h"

Q_GLOBAL_STATIC(QStringList, strings);

int getIndex(const QString& str) {
    int idx = strings()->indexOf(str);
    if (idx > -1) return idx;
    strings()->append(str);
    return strings()->count() - 1;
}

IndexedString::IndexedString() : m_index(0) {
}

///@param str must be a utf8 encoded string, does not need to be 0-terminated.
///@param length must be its length in bytes.
IndexedString::IndexedString( const char* str, unsigned short length, unsigned int hash ) {
  if(!length)
    m_index = 0;
  else if(length == 1)
    m_index = 0xffff0000 | str[0];
  else {
    m_index = getIndex(QString::fromUtf8(str, length));
    /*QMutexLocker lock(globalIndexedStringRepository->mutex());
    
    m_index = globalIndexedStringRepository->index(IndexedStringRepositoryItemRequest(str, hash ? hash : hashString(str, length), length));
    
    if(shouldDoDUChainReferenceCounting(this))
      increase(globalIndexedStringRepository->dynamicItemFromIndexSimple(m_index)->refCount);*/
  }
}

IndexedString::IndexedString( char c ) {
  m_index = 0xffff0000 | c;
}

IndexedString::IndexedString( const QUrl& url ) {
  QByteArray array(url.path().toUtf8());

  const char* str = array.constData();

  int size = array.size();

  if(!size)
    m_index = 0;
  else if(size == 1)
    m_index = 0xffff0000 | str[0];
  else {
    m_index = getIndex(QString::fromUtf8(str));
    /*QMutexLocker lock(globalIndexedStringRepository->mutex());
    m_index = globalIndexedStringRepository->index(IndexedStringRepositoryItemRequest(str, hashString(str, size), size));
    
    if(shouldDoDUChainReferenceCounting(this))
      increase(globalIndexedStringRepository->dynamicItemFromIndexSimple(m_index)->refCount);*/
  }
}

IndexedString::IndexedString( const QString& string ) {
  QByteArray array(string.toUtf8());

  const char* str = array.constData();

  int size = array.size();

  if(!size)
    m_index = 0;
  else if(size == 1)
    m_index = 0xffff0000 | str[0];
  else {
    m_index = getIndex(string);
    /*QMutexLocker lock(globalIndexedStringRepository->mutex());
    m_index = globalIndexedStringRepository->index(IndexedStringRepositoryItemRequest(str, hashString(str, size), size));

    if(shouldDoDUChainReferenceCounting(this))
      increase(globalIndexedStringRepository->dynamicItemFromIndexSimple(m_index)->refCount);*/



( run in 1.493 second using v1.01-cache-2.11-cpan-e93a5daba3e )