aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Moenicke <thomas.moenicke@nokia.com>2010-11-11 15:17:19 +0200
committerArmin Berres <armin.berres@basyskom.de>2011-01-06 11:21:11 +0100
commit007270faed92e3ca9d2631d490c0a757a1f668b4 (patch)
tree7d3650319975e216f8b091d478b8579e9c3040f3
parent592508a26ae899a86392eeabca09404afd470f5b (diff)
Changes: replace strings by ids in style classes and style attributes
RevBy: Armin Berres, Peter Penz Details: Strings for names, types and keywords are passed around as unique integers to reduce overhead with string operations. The strings and the mapping to ids are stored in a mmaped file. The memory of all strings will be shared between application. This part has been written by Armin Berres.
-rw-r--r--benchmarks/pt_mstylesheet/pt_mstylesheet.pro2
-rw-r--r--src/corelib/style/mstylesheet.cpp40
-rw-r--r--src/corelib/style/mstylesheet_p.h4
-rw-r--r--src/corelib/style/mstylesheetattribute.cpp9
-rw-r--r--src/corelib/style/mstylesheetattribute.h9
-rw-r--r--src/corelib/style/mstylesheetparser.cpp92
-rw-r--r--src/corelib/style/mstylesheetselector.cpp107
-rw-r--r--src/corelib/style/mstylesheetselector.h34
-rw-r--r--src/corelib/style/mstylesheetselector_p.h16
-rw-r--r--src/corelib/style/muniquestringcache.cpp279
-rw-r--r--src/corelib/style/muniquestringcache.h37
-rw-r--r--src/corelib/style/style.pri9
-rw-r--r--tests/ft_mstylesheet/ft_mstylesheet.pro4
-rw-r--r--tests/ft_mstylesheetparser/ft_mstylesheetparser.cpp165
-rw-r--r--tests/ft_mstylesheetparser/ft_mstylesheetparser.pro7
-rw-r--r--tests/ut_mlogicalvalues/ut_mlogicalvalues.pro7
16 files changed, 599 insertions, 222 deletions
diff --git a/benchmarks/pt_mstylesheet/pt_mstylesheet.pro b/benchmarks/pt_mstylesheet/pt_mstylesheet.pro
index 1755cd7f..55f80b93 100644
--- a/benchmarks/pt_mstylesheet/pt_mstylesheet.pro
+++ b/benchmarks/pt_mstylesheet/pt_mstylesheet.pro
@@ -8,7 +8,9 @@ TARGET = pt_mstylesheet
SOURCES += pt_mstylesheet.cpp \
mlogicalvalues.cpp \
mstylesheetattribute.cpp \
+ muniquestringcache.cpp
HEADERS += pt_mstylesheet.h \
mlogicalvalues.h \
mstylesheetattribute.h \
+ muniquestringcache.h
diff --git a/src/corelib/style/mstylesheet.cpp b/src/corelib/style/mstylesheet.cpp
index 95911214..4d3bd20c 100644
--- a/src/corelib/style/mstylesheet.cpp
+++ b/src/corelib/style/mstylesheet.cpp
@@ -319,7 +319,7 @@ MStyleSheetPrivate::CacheEntry *MStyleSheetPrivate::buildCacheEntry(const QList<
MAttributeList::const_iterator attributesEnd = selector->attributes()->constEnd();
for (MAttributeList::const_iterator j = selector->attributes()->constBegin(); j != attributesEnd; ++j) {
- QByteArray propertyName = j.key();
+ MUniqueStringCache::Index propertyName = j.key();
CacheEntry::iterator iter = (*entry).find(propertyName);
// Check if these settings are already in the list
@@ -371,7 +371,7 @@ bool MStyleSheetPrivate::combine(MStyle *style, const CacheEntry &entry, const S
// check all the attributes of this selector against the cached entry
foreach(MStyleSheetAttribute * attribute, *(info.selector->attributes())) {
- MOriginContainer *old = data.value(attribute->getName(), NULL);
+ MOriginContainer *old = data.value(attribute->getNameID(), NULL);
if (old && !isHigherPriority(old, info.selector, info.classPriority, info.parentPriority)) {
continue;
}
@@ -381,7 +381,7 @@ bool MStyleSheetPrivate::combine(MStyle *style, const CacheEntry &entry, const S
info.classPriority,
info.parentPriority,
info.filename, info.stylesheet);
- data[attribute->getName()] = tempMOriginCont;
+ data[attribute->getNameID()] = tempMOriginCont;
tempMOriginContainers.append(tempMOriginCont);
}
}
@@ -395,7 +395,7 @@ bool MStyleSheetPrivate::combine(MStyle *style, const CacheEntry &entry, const S
bool propertyInitialized = false;
// find matching attribute from hash
- CacheEntry::iterator iterator = data.find(QByteArray(style->metaObject()->property(i).name()));
+ CacheEntry::iterator iterator = data.find(MUniqueStringCache::stringToIndex(style->metaObject()->property(i).name()));
if (iterator != data.end()) {
// get the attribute value
@@ -461,20 +461,32 @@ bool MStyleSheetPrivate::isHigherPriority(MOriginContainer *prev,
{
// At this stage we either have a correct object name or we don't have object name at all.
// So, select the one which has it. If both have same name or neither one has it, go further.
- int objectName = selector->objectName().length() - prev->selector->objectName().length();
- if (objectName != 0)
- return (objectName < 0) ? false : true;
+
+ if (selector->objectNameID() != prev->selector->objectNameID()) {
+ if (selector->objectNameID() != MUniqueStringCache::EmptyStringIndex) {
+ return true;
+ } else {
+ return false;
+ }
+ }
// Only other has mode, mode is more important than orientation
- int mode = selector->mode().length() - prev->selector->mode().length();
- if (mode != 0)
- return (mode < 0) ? false : true;
+ if (selector->modeID() != prev->selector->modeID()) {
+ if (selector->modeID() != MUniqueStringCache::EmptyStringIndex) {
+ return true;
+ } else {
+ return false;
+ }
+ }
// Other one has class type and another doesn't have it
- int classType = selector->classType().length() - prev->selector->classType().length();
- if (classType != 0)
- return (classType < 0) ? false : true;
-
+ if (selector->classTypeID() != prev->selector->classTypeID()) {
+ if (selector->classTypeID() != MUniqueStringCache::EmptyStringIndex) {
+ return true;
+ } else {
+ return false;
+ }
+ }
// The closer one in the scene chain has more priority, 0xffff means no match
unsigned int sceneOrder = EXTRACT_SCENEORDER(parentPriority);
diff --git a/src/corelib/style/mstylesheet_p.h b/src/corelib/style/mstylesheet_p.h
index 5335ab14..b17d9e80 100644
--- a/src/corelib/style/mstylesheet_p.h
+++ b/src/corelib/style/mstylesheet_p.h
@@ -27,6 +27,8 @@
#define EXTRACT_SCENEORDER(priority) (priority >> 16)
#define EXTRACT_INHERITANCEORDER(priority) (priority & 0xffff)
+#include "muniquestringcache.h"
+
#include <QObject>
#include <QString>
#include <QList>
@@ -115,7 +117,7 @@ public:
const QByteArray &type,
M::Orientation orientation);
- typedef QHash<QByteArray, MOriginContainer *> CacheEntry;
+ typedef QHash<MUniqueStringCache::Index, MOriginContainer *> CacheEntry;
static QHash<QByteArray, CacheEntry *> EntryCache;
static QHash<QByteArray, MStyle *> StyleCache;
diff --git a/src/corelib/style/mstylesheetattribute.cpp b/src/corelib/style/mstylesheetattribute.cpp
index 0b6f6321..04e19d43 100644
--- a/src/corelib/style/mstylesheetattribute.cpp
+++ b/src/corelib/style/mstylesheetattribute.cpp
@@ -265,7 +265,7 @@ namespace {
static QtDatatypeConverter DataTypeConverter;
-MStyleSheetAttribute::MStyleSheetAttribute(const QByteArray& name, const QByteArray& value, qint64 position)
+MStyleSheetAttribute::MStyleSheetAttribute(MUniqueStringCache::Index name, const QByteArray& value, qint64 position)
: name(name), value(value), position(position)
{
}
@@ -279,6 +279,11 @@ MStyleSheetAttribute::MStyleSheetAttribute(const MStyleSheetAttribute &other)
QByteArray MStyleSheetAttribute::getName()
{
+ return MUniqueStringCache::indexToString(name);
+}
+
+MUniqueStringCache::Index MStyleSheetAttribute::getNameID()
+{
return name;
}
@@ -811,7 +816,7 @@ bool MStyleSheetAttribute::writeAttribute(const QString &filename,
}
}
- MStyleSheetParser::outputParseError(filename, "Not a valid attribute(" + QLatin1String(property.typeName()) + "): " + name + ": " + value, MStyleSheetParser::getLineNum(filename, position));
+ MStyleSheetParser::outputParseError(filename, "Not a valid attribute(" + QLatin1String(property.typeName()) + "): " + MUniqueStringCache::indexToString(name) + " : " + value, MStyleSheetParser::getLineNum(filename, position));
return false;
}
diff --git a/src/corelib/style/mstylesheetattribute.h b/src/corelib/style/mstylesheetattribute.h
index d4954062..6a206bd4 100644
--- a/src/corelib/style/mstylesheetattribute.h
+++ b/src/corelib/style/mstylesheetattribute.h
@@ -29,7 +29,7 @@
#include "mnamespace.h"
#include "mstyle.h"
#include "mshareddata.h"
-
+#include "muniquestringcache.h"
//! \internal
/*! An attribute of a style sheet selector.
@@ -46,10 +46,11 @@ class MStyleSheetAttribute
};
public:
- MStyleSheetAttribute(const QByteArray& name, const QByteArray& value, qint64 position);
+ MStyleSheetAttribute(MUniqueStringCache::Index name, const QByteArray& value, qint64 position);
MStyleSheetAttribute(const MStyleSheetAttribute &other);
QByteArray getName();
+ MUniqueStringCache::Index getNameID();
QByteArray getValue();
qint64 getPosition();
@@ -79,14 +80,14 @@ private:
bool fillProperty(const QMetaProperty &property, MStyle *style, CacheOrientationFlags cacheOrientation,
const QVariant &variant, bool cache = true);
- QByteArray name;
+ MUniqueStringCache::Index name;
QByteArray value;
qint64 position; //used for providing detailed css parse error output (linenumber)
friend class MStyleSheetParserPrivate;
};
-typedef QMap<QByteArray, MStyleSheetAttribute *> MAttributeList;
+typedef QMap<MUniqueStringCache::Index, MStyleSheetAttribute *> MAttributeList;
//! \internal_end
#endif
diff --git a/src/corelib/style/mstylesheetparser.cpp b/src/corelib/style/mstylesheetparser.cpp
index a5de7385..e5e413c7 100644
--- a/src/corelib/style/mstylesheetparser.cpp
+++ b/src/corelib/style/mstylesheetparser.cpp
@@ -31,6 +31,7 @@
#include <QColor>
#include <QDir>
#include <QDateTime>
+#include <QList>
#ifndef Q_OS_WIN
#include <utime.h>
@@ -39,7 +40,7 @@
#include <sys/stat.h>
namespace {
- const unsigned int FILE_VERSION = 17;
+ const unsigned int FILE_VERSION = 18;
}
#ifndef DOXYGEN_SHOULD_SKIP_THIS
@@ -60,7 +61,7 @@ public:
bool parse(QFile &file, const QFileInfo &fileInfo, bool validateOnly = false);
MStyleSheetSelector *parseSelector(QFile &stream, bool *error, bool validateOnly);
- QPair<QByteArray, MStyleSheetAttribute *> parseAttribute(QFile &stream, QChar &endCharacter, bool validateOnly);
+ MStyleSheetAttribute* parseAttribute(QFile &stream, QChar &endCharacter, bool validateOnly);
bool parseAtToken(QFile &stream, bool validateOnly = false);
bool importFile(const QByteArray &importedFileName, bool validateOnly = false);
int getMatchIndex(const QByteArray &str, const QByteArray &charList, int from = 0) const;
@@ -90,7 +91,7 @@ public:
void writeStylesheetFileInfo(MStyleSheetParser::StylesheetFileInfo *selector, QDataStream &stream);
MStyleSheetParser::StylesheetFileInfo * readStylesheetFileInfo(QDataStream &stream);
- MStyleSheetSelector *readSelector(const QByteArray &file, QDataStream &stream);
+ MStyleSheetSelector *readSelector(QDataStream &stream);
void writeSelector(MStyleSheetSelector *selector, QDataStream &stream);
static QString getOrientationName(MStyleSheetSelector::Orientation orientation);
@@ -117,7 +118,7 @@ public:
bool validName(const QByteArray &name);
bool validValue(const QByteArray &value);
-
+
//cache for frequently used byte arrays to reduce dynamic memory allocations made
//by byte arrays in stylesheet (attributeName, attributeValue, className, selectorName etc.)
static QSet<QByteArray> stringCache;
@@ -458,10 +459,10 @@ bool MStyleSheetParserPrivate::parse(QFile &file, const QFileInfo &fileInfo, boo
bool error;
MStyleSheetSelector *selector = parseSelector(file, &error, validateOnly);
skipWhiteSpace(file);
- if (selector && validateOnly) {
- delete selector;
- selector = 0;
- }
+ if (selector && validateOnly) {
+ delete selector;
+ selector = 0;
+ }
if (!selector && error) {
// It wasn't selector.. there was an error..
// we don't really know what it is then so fail.
@@ -818,16 +819,16 @@ MStyleSheetSelector *MStyleSheetParserPrivate::parseSelector(QFile &stream, bool
qint64 startSelector = startReadPos;
-
- MStyleSheetSelector *selector = new MStyleSheetSelector(cachedString(objectName),
- cachedString(className),
- cachedString(classType),
+ MStyleSheetSelector *selector = new MStyleSheetSelector(
+ MUniqueStringCache::stringToIndex(objectName),
+ MUniqueStringCache::stringToIndex(className),
+ MUniqueStringCache::stringToIndex(classType),
getOrientationFromName(cachedString(orientation)),
- cachedString(mode),
- cachedString(parsedFileName),
- cachedString(parentName),
- parentObjectName,
- (MStyleSheetSelector::Flags) flags);
+ MUniqueStringCache::stringToIndex(mode),
+ MUniqueStringCache::stringToIndex(parentName),
+ MUniqueStringCache::stringToIndex(parentObjectName),
+ (MStyleSheetSelector::Flags) flags
+ );
// mDebug("MStyleSheetParserPrivate") << "selector found: " << selector->className() << selector->objectName();
char peek;
@@ -852,8 +853,8 @@ MStyleSheetSelector *MStyleSheetParserPrivate::parseSelector(QFile &stream, bool
// Parse attribute, if it fails, terminate
QChar character;
- QPair<QByteArray, MStyleSheetAttribute *> result = parseAttribute(stream, character, validateOnly);
- if (!result.second) {
+ MStyleSheetAttribute* result = parseAttribute(stream, character, validateOnly);
+ if (!result) {
mWarning("MStyleSheetParserPrivate") << "Attribute read failed in selector: " <<
selector->className() + '[' + selector->classType() + "]#" + selector->objectName();
@@ -865,11 +866,11 @@ MStyleSheetSelector *MStyleSheetParserPrivate::parseSelector(QFile &stream, bool
}
if (validateOnly) {
- delete result.second;
+ delete result;
}
else {
// Store and parse next
- selector->attributes()->insert(result.first, result.second);
+ selector->attributes()->insert(result->name, result);
}
// last character was closing the whole selector -> we're done
@@ -898,7 +899,7 @@ MStyleSheetSelector *MStyleSheetParserPrivate::parseSelector(QFile &stream, bool
return NULL;
}
-QPair<QByteArray, MStyleSheetAttribute *> MStyleSheetParserPrivate::parseAttribute(QFile &stream, QChar &character, bool validateOnly)
+MStyleSheetAttribute* MStyleSheetParserPrivate::parseAttribute(QFile &stream, QChar &character, bool validateOnly)
{
QByteArray name;
QByteArray value;
@@ -911,13 +912,12 @@ QPair<QByteArray, MStyleSheetAttribute *> MStyleSheetParserPrivate::parseAttribu
character = read(stream, ";}", value);
if (((character == ';') || (character == '}')) && validValue(value)) {
+
MStyleSheetAttribute *result = new MStyleSheetAttribute(
- cachedString(MStyleSheetAttribute::attributeNameToPropertyName(name)),
+ MUniqueStringCache::stringToIndex(cachedString(MStyleSheetAttribute::attributeNameToPropertyName(name))),
cachedString(value),
startReadPos);
- //if value contains const references save the original value
- //string before replacing const references with real values
if (!validateOnly && replaceConsts(result->value)) {
result->value = cachedString(result->value);
if (!validValue(result->value)) {
@@ -925,7 +925,7 @@ QPair<QByteArray, MStyleSheetAttribute *> MStyleSheetParserPrivate::parseAttribu
}
}
- return QPair<QByteArray, MStyleSheetAttribute *>(result->name, result);
+ return result;
} else {
outputParseError(parsedFileName, "Parse attribute failed, ';' or '}' is missing after value or the value is invalid. Multiline attributes are not supported.", getLineNum(stream, startReadPos));
}
@@ -933,7 +933,7 @@ QPair<QByteArray, MStyleSheetAttribute *> MStyleSheetParserPrivate::parseAttribu
outputParseError(parsedFileName, "Parse attribute failed, ':' is missing after name or the name is invalid.", getLineNum(stream, startReadPos));
}
- return QPair<QByteArray, MStyleSheetAttribute *> ("", NULL);
+ return 0;
}
QString MStyleSheetParserPrivate::createBinaryFilename(const QString &filename) const
@@ -1115,6 +1115,7 @@ bool MStyleSheetParserPrivate::dump(const QString &binaryFilename)
QDataStream stream(&file);
stream << FILE_VERSION;
stream << timestamps;
+
if (logicalValues) {
stream << logicalValues->timestamps();
} else {
@@ -1168,23 +1169,23 @@ MStyleSheetParser::StylesheetFileInfo * MStyleSheetParserPrivate::readStylesheet
stream >> selectorCount;
// read all selectors without parent
for (int i = 0; i < selectorCount; ++i) {
- MStyleSheetSelector *selector = readSelector(fi->filename, stream);
+ MStyleSheetSelector *selector = readSelector(stream);
fi->selectors.push_back(selector);
}
// read all selectors with parent
stream >> selectorCount;
for (int i = 0; i < selectorCount; ++i) {
- MStyleSheetSelector *selector = readSelector(fi->filename, stream);
+ MStyleSheetSelector *selector = readSelector(stream);
fi->parentSelectors.push_back(selector);
}
return fi;
}
-MStyleSheetSelector *MStyleSheetParserPrivate::readSelector(const QByteArray &file, QDataStream &stream)
+MStyleSheetSelector *MStyleSheetParserPrivate::readSelector(QDataStream &stream)
{
- QByteArray parentName, parentObjectName, objectName, className, classType, mode;
+ MUniqueStringCache::Index parentName, parentObjectName, objectName, className, classType, mode;
int flags, orientation;
stream >> parentName;
@@ -1196,18 +1197,12 @@ MStyleSheetSelector *MStyleSheetParserPrivate::readSelector(const QByteArray &fi
stream >> orientation;
stream >> mode;
- parentName = cachedString(parentName);
- objectName = cachedString(objectName);
- className = cachedString(className);
- classType = cachedString(classType);
- mode = cachedString(mode);
-
- MStyleSheetSelector *selector = new MStyleSheetSelector(objectName,
+ MStyleSheetSelector *selector = new MStyleSheetSelector(
+ objectName,
className,
classType,
(MStyleSheetSelector::Orientation) orientation,
mode,
- file,
parentName,
parentObjectName,
(MStyleSheetSelector::Flags) flags);
@@ -1219,7 +1214,8 @@ MStyleSheetSelector *MStyleSheetParserPrivate::readSelector(const QByteArray &fi
// read attributes one by one
for (int attributeIndex = 0; attributeIndex < attributeCount; ++attributeIndex) {
- QByteArray name;
+
+ MUniqueStringCache::Index name;
stream >> name;
QByteArray value;
stream >> value;
@@ -1227,7 +1223,7 @@ MStyleSheetSelector *MStyleSheetParserPrivate::readSelector(const QByteArray &fi
stream >> position;
MStyleSheetAttribute *attribute = new MStyleSheetAttribute(
- cachedString(name),
+ name,
cachedString(value),
position);
@@ -1239,14 +1235,14 @@ MStyleSheetSelector *MStyleSheetParserPrivate::readSelector(const QByteArray &fi
void MStyleSheetParserPrivate::writeSelector(MStyleSheetSelector *selector, QDataStream &stream)
{
- stream << selector->parentName();
- stream << selector->parentObjectName();
+ stream << selector->parentNameID();
+ stream << selector->parentObjectNameID();
stream << (int) selector->flags();
- stream << selector->objectName();
- stream << selector->className();
- stream << selector->classType();
+ stream << selector->objectNameID();
+ stream << selector->classNameID();
+ stream << selector->classTypeID();
stream << (int) selector->orientation();
- stream << selector->mode();
+ stream << selector->modeID();
stream << selector->attributes()->count();
@@ -1258,13 +1254,11 @@ void MStyleSheetParserPrivate::writeSelector(MStyleSheetSelector *selector, QDat
<< __FILE__ << "line:" << __LINE__ << "function:"
<< __PRETTY_FUNCTION__;
}
-
MAttributeList::const_iterator attributesEnd = selector->attributes()->constEnd();
for (MAttributeList::const_iterator attributeIterator = selector->attributes()->constBegin();
attributeIterator != attributesEnd;
++attributeIterator) {
-
stream << attributeIterator.value()->name;
stream << attributeIterator.value()->value;
stream << attributeIterator.value()->position;
diff --git a/src/corelib/style/mstylesheetselector.cpp b/src/corelib/style/mstylesheetselector.cpp
index e7ee7e27..e8e50556 100644
--- a/src/corelib/style/mstylesheetselector.cpp
+++ b/src/corelib/style/mstylesheetselector.cpp
@@ -23,20 +23,19 @@
void MStyleSheetSelectorPrivate::operator=(const MStyleSheetSelectorPrivate &other)
{
- objName = other.objName;
- clName = other.clName;
- clType = other.clType;
+ objectName = other.objectName;
+ className = other.className;
+ classType = other.classType;
screenOrientation = other.screenOrientation;
objectMode = other.objectMode;
- filename = other.filename;
parentName = other.parentName;
parentObjectName = other.parentObjectName;
flags = other.flags;
// copy attributes
- MAttributeList::const_iterator otherDataEnd = other.data.constEnd();
+ MAttributeList::const_iterator otherAttributesEnd = other.attributes.constEnd();
- for (MAttributeList::const_iterator iterator = other.data.begin(); iterator != otherDataEnd; ++iterator) {
+ for (MAttributeList::const_iterator iterator = other.attributes.begin(); iterator != otherAttributesEnd; ++iterator) {
// attribute to copy
MStyleSheetAttribute *source = *iterator;
@@ -44,51 +43,47 @@ void MStyleSheetSelectorPrivate::operator=(const MStyleSheetSelectorPrivate &oth
MStyleSheetAttribute *copy = new MStyleSheetAttribute(*source);
// add copy of attribute to data list
- data.insert(iterator.key(), copy);
+ attributes.insert(iterator.key(), copy);
}
}
-MStyleSheetSelector::MStyleSheetSelector(const QByteArray &objectName,
- const QByteArray &className,
- const QByteArray &classType,
+MStyleSheetSelector::MStyleSheetSelector(const MUniqueStringCache::Index objectName,
+ const MUniqueStringCache::Index className,
+ const MUniqueStringCache::Index classType,
const Orientation orientation,
- const QByteArray &mode,
- const QByteArray &filename,
- const QByteArray &parentName,
+ const MUniqueStringCache::Index mode,
+ const MUniqueStringCache::Index parentName,
Flags flags) :
d_ptr(new MStyleSheetSelectorPrivate)
{
Q_D(MStyleSheetSelector);
- d->objName = objectName;
- d->clName = className;
- d->clType = classType;
+ d->objectName = objectName;
+ d->className = className;
+ d->classType = classType;
d->screenOrientation = orientation;
d->objectMode = mode;
- d->filename = filename;
d->parentName = parentName;
- d->parentObjectName = QByteArray();
+ d->parentObjectName = MUniqueStringCache::UndefinedIndex;
d->flags = flags;
}
-MStyleSheetSelector::MStyleSheetSelector(const QByteArray &objectName,
- const QByteArray &className,
- const QByteArray &classType,
+MStyleSheetSelector::MStyleSheetSelector(const MUniqueStringCache::Index objectName,
+ const MUniqueStringCache::Index className,
+ const MUniqueStringCache::Index classType,
const Orientation orientation,
- const QByteArray &mode,
- const QByteArray &filename,
- const QByteArray &parentName,
- const QByteArray &parentObjectName,
+ const MUniqueStringCache::Index mode,
+ const MUniqueStringCache::Index parentName,
+ const MUniqueStringCache::Index parentObjectName,
Flags flags) :
d_ptr(new MStyleSheetSelectorPrivate)
{
Q_D(MStyleSheetSelector);
- d->objName = objectName;
- d->clName = className;
- d->clType = classType;
+ d->objectName = objectName;
+ d->className = className;
+ d->classType = classType;
d->screenOrientation = orientation;
d->objectMode = mode;
- d->filename = filename;
d->parentName = parentName;
d->parentObjectName = parentObjectName;
d->flags = flags;
@@ -104,8 +99,8 @@ MStyleSheetSelector::~MStyleSheetSelector()
{
Q_D(MStyleSheetSelector);
- qDeleteAll(d->data);
- d->data.clear();
+ qDeleteAll(d->attributes);
+ d->attributes.clear();
delete d_ptr;
}
@@ -113,37 +108,37 @@ MStyleSheetSelector::~MStyleSheetSelector()
MAttributeList *MStyleSheetSelector::attributes()
{
Q_D(MStyleSheetSelector);
- return &d->data;
+ return &d->attributes;
}
QByteArray MStyleSheetSelector::parentName() const
{
Q_D(const MStyleSheetSelector);
- return d->parentName;
+ return MUniqueStringCache::indexToString(d->parentName);
}
QByteArray MStyleSheetSelector::parentObjectName() const
{
Q_D(const MStyleSheetSelector);
- return d->parentObjectName;
+ return MUniqueStringCache::indexToString(d->parentObjectName);
}
QByteArray MStyleSheetSelector::objectName() const
{
Q_D(const MStyleSheetSelector);
- return d->objName;
+ return MUniqueStringCache::indexToString(d->objectName);
}
QByteArray MStyleSheetSelector::className() const
{
Q_D(const MStyleSheetSelector);
- return d->clName;
+ return MUniqueStringCache::indexToString(d->className);
}
QByteArray MStyleSheetSelector::classType() const
{
Q_D(const MStyleSheetSelector);
- return d->clType;
+ return MUniqueStringCache::indexToString(d->classType);
}
MStyleSheetSelector::Orientation MStyleSheetSelector::orientation() const
@@ -155,7 +150,7 @@ MStyleSheetSelector::Orientation MStyleSheetSelector::orientation() const
QByteArray MStyleSheetSelector::mode() const
{
Q_D(const MStyleSheetSelector);
- return d->objectMode;
+ return MUniqueStringCache::indexToString(d->objectMode);
}
MStyleSheetSelector::Flags MStyleSheetSelector::flags() const
@@ -164,4 +159,40 @@ MStyleSheetSelector::Flags MStyleSheetSelector::flags() const
return d->flags;
}
+MUniqueStringCache::Index MStyleSheetSelector::objectNameID() const
+{
+ Q_D(const MStyleSheetSelector);
+ return d->objectName;
+}
+
+MUniqueStringCache::Index MStyleSheetSelector::classNameID() const
+{
+ Q_D(const MStyleSheetSelector);
+ return d->className;
+}
+
+MUniqueStringCache::Index MStyleSheetSelector::classTypeID() const
+{
+ Q_D(const MStyleSheetSelector);
+ return d->classType;
+}
+
+MUniqueStringCache::Index MStyleSheetSelector::modeID() const
+{
+ Q_D(const MStyleSheetSelector);
+ return d->objectMode;
+}
+
+MUniqueStringCache::Index MStyleSheetSelector::parentNameID() const
+{
+ Q_D(const MStyleSheetSelector);
+ return d->parentName;
+}
+
+MUniqueStringCache::Index MStyleSheetSelector::parentObjectNameID() const
+{
+ Q_D(const MStyleSheetSelector);
+ return d->parentObjectName;
+}
+
diff --git a/src/corelib/style/mstylesheetselector.h b/src/corelib/style/mstylesheetselector.h
index a3f051ae..e9cfda21 100644
--- a/src/corelib/style/mstylesheetselector.h
+++ b/src/corelib/style/mstylesheetselector.h
@@ -22,6 +22,7 @@
#include "mexport.h"
#include "mstylesheetattribute.h"
+#include "muniquestringcache.h"
#include <QByteArray>
#include <QVariant>
@@ -67,16 +68,15 @@ public:
* \param subclasses A flag indicating whether the su
* \deprecated Please use the new constructor
*/
-
- explicit MStyleSheetSelector(const QByteArray &objectName = "",
- const QByteArray &className = "",
- const QByteArray &classType = "",
+ explicit MStyleSheetSelector(MUniqueStringCache::Index objectName = MUniqueStringCache::UndefinedIndex,
+ MUniqueStringCache::Index className = MUniqueStringCache::UndefinedIndex,
+ MUniqueStringCache::Index classType = MUniqueStringCache::UndefinedIndex,
const Orientation orientation = UndefinedOrientation,
- const QByteArray &mode = "",
- const QByteArray &filename = "",
- const QByteArray &parentName = "",
+ MUniqueStringCache::Index mode = MUniqueStringCache::UndefinedIndex,
+ MUniqueStringCache::Index parentName = MUniqueStringCache::UndefinedIndex,
Flags flags = (Flags) 0);
+
/*!
* MStyleSheetSelector constructor
* \param objectName target object name of this selector, can be empty
@@ -93,16 +93,20 @@ public:
* \param subclasses A flag indicating whether the su
*/
- explicit MStyleSheetSelector(const QByteArray &objectName,
- const QByteArray &className,
- const QByteArray &classType,
+ explicit MStyleSheetSelector(MUniqueStringCache::Index objectName,
+ MUniqueStringCache::Index className,
+ MUniqueStringCache::Index classType,
const Orientation orientation,
- const QByteArray &mode,
- const QByteArray &filename,
- const QByteArray &parentName,
- const QByteArray &parentObjectName,
+ MUniqueStringCache::Index mode,
+ MUniqueStringCache::Index parentName,
+ MUniqueStringCache::Index parentObjectName,
Flags flags = (Flags) 0);
-
+ MUniqueStringCache::Index objectNameID() const;
+ MUniqueStringCache::Index classNameID() const;
+ MUniqueStringCache::Index classTypeID() const;
+ MUniqueStringCache::Index modeID() const;
+ MUniqueStringCache::Index parentNameID() const;
+ MUniqueStringCache::Index parentObjectNameID() const;
/*!
* Copy constructor
diff --git a/src/corelib/style/mstylesheetselector_p.h b/src/corelib/style/mstylesheetselector_p.h
index 0f41615d..ee04304c 100644
--- a/src/corelib/style/mstylesheetselector_p.h
+++ b/src/corelib/style/mstylesheetselector_p.h
@@ -27,23 +27,23 @@ class MStyleSheetSelectorPrivate
{
public:
//! Parent class name, represented by this selector.
- QByteArray parentName;
+ MUniqueStringCache::Index parentName;
//! Parent class object name, represented by this selector.
- QByteArray parentObjectName;
+ MUniqueStringCache::Index parentObjectName;
//! Object name, represented by this selector.
- QByteArray objName;
+ MUniqueStringCache::Index objectName;
//! Class name, represented by this selector.
- QByteArray clName;
+ MUniqueStringCache::Index className;
//! Type, represented by this selector.
- QByteArray clType;
+ MUniqueStringCache::Index classType;
//! Screen orientation type, represented by this selector.
MStyleSheetSelector::Orientation screenOrientation;
//! Object mode, represented by this selector.
- QByteArray objectMode;
+ MUniqueStringCache::Index objectMode;
//! Attribute list of this selector (ClassName#ObjectName.Orientation:Mode).
- MAttributeList data;
+ MAttributeList attributes;
//! Name of the css file where the selector was created.
- QByteArray filename;
+ MUniqueStringCache::Index fileName;
//! Flags indicating whether this is a special kind of selector.
MStyleSheetSelector::Flags flags;
diff --git a/src/corelib/style/muniquestringcache.cpp b/src/corelib/style/muniquestringcache.cpp
new file mode 100644
index 00000000..b70d2f77
--- /dev/null
+++ b/src/corelib/style/muniquestringcache.cpp
@@ -0,0 +1,279 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#include "muniquestringcache.h"
+
+#include "mdebug.h"
+
+#include <QFile>
+#include <QFileInfo>
+#include <QDir>
+#include <QSystemSemaphore>
+#include <QHash>
+#include <QByteArray>
+#include <QElapsedTimer>
+
+const int MAX_CACHE_SIZE = 1024*1024;
+#define CACHE_NAME "MTF_UNIQUE_STRING_CACHE"
+
+class UniqueStringCacheMappedMemory
+{
+public:
+ UniqueStringCacheMappedMemory()
+ : cacheFile(createCacheFileName()),
+ accessSemaphore(QLatin1String(CACHE_NAME "_SEMAPHORE"), 1),
+ attached(false)
+ {
+ if (!accessSemaphore.acquire()) {
+ qWarning() << "Unable to aquire semaphore:" << accessSemaphore.errorString();
+ return;
+ }
+
+ attachToCache();
+
+ accessSemaphore.release();
+ }
+
+ bool isAttached() const { return attached; }
+
+ uchar* data() { return rawMappedMemory; }
+ QString errorString() { return accessSemaphore.errorString(); }
+
+ ~UniqueStringCacheMappedMemory()
+ {
+ }
+
+private:
+ friend class UniqueStringCacheMappedMemoryLocker;
+ bool lock() { return accessSemaphore.acquire(); }
+ bool unlock() { return accessSemaphore.release(); }
+
+ void attachToCache()
+ {
+ if (!cacheFile.exists()) {
+ if (!initializeCache()) {
+ attached = false;
+ return;
+ }
+ }
+
+ if (!cacheFile.open(QIODevice::ReadWrite)) {
+ mWarning("UniqueStringCacheMappedMemory") << "Could not open" <<
+ cacheFile.fileName();
+ return;
+ }
+
+ if (cacheFile.size() != MAX_CACHE_SIZE) {
+ mWarning("UniqueStringCacheMappedMemory") << "Wrong cache file size" <<
+ cacheFile.size() << "Expected:" << MAX_CACHE_SIZE;
+ return;
+ }
+
+ rawMappedMemory = cacheFile.map(0, MAX_CACHE_SIZE);
+
+ attached = true;
+
+ cacheFile.close();
+ }
+
+ bool initializeCache() {
+ if (!cacheFile.open(QFile::WriteOnly)) {
+ //Maybe it failed because the directory doesn't exist
+ QDir().mkpath(QFileInfo(cacheFile.fileName()).absolutePath());
+ if (!cacheFile.open(QFile::WriteOnly)) {
+ mWarning("UniqueStringCacheMappedMemory") <<
+ "Wrong permissions for cache directory. Cannot create" <<
+ cacheFile.fileName();
+ return false;
+ }
+ }
+ cacheFile.resize(MAX_CACHE_SIZE);
+ cacheFile.close();
+ return true;
+ }
+
+ QString createCacheFileName() {
+ return QString(CACHEDIR) + "/css/" + CACHE_NAME;
+ }
+
+ QFile cacheFile;
+ QSystemSemaphore accessSemaphore;
+ uchar* rawMappedMemory;
+ bool attached;
+};
+
+Q_GLOBAL_STATIC(UniqueStringCacheMappedMemory, uniqueStringCacheMappedMemory)
+
+
+class UniqueStringCacheMappedMemoryLocker
+{
+public:
+ UniqueStringCacheMappedMemoryLocker(UniqueStringCacheMappedMemory *cache)
+ : cache(cache->lock() ? cache : (UniqueStringCacheMappedMemory *)0)
+ {
+ if (!cache) {
+ mWarning("UniqueStringCacheMappedMemoryLocker") << "Unable to lock unique string cache" << cache->errorString();
+ }
+ }
+
+ bool isLocked() const
+ {
+ return cache;
+ }
+
+ ~UniqueStringCacheMappedMemoryLocker()
+ {
+ if (!cache) {
+ return;
+ }
+ if (!cache->unlock()) {
+ mWarning("UniqueStringCacheMappedMemoryLocker") << "Unable to unlock unique string cache" << cache->errorString();
+ }
+ }
+
+private:
+ UniqueStringCacheMappedMemory *cache;
+};
+
+// mapping id => string
+typedef QVector<QByteArray> IdToStringCache;
+Q_GLOBAL_STATIC(IdToStringCache, idToStringCache)
+// mapping string => id
+typedef QHash<QByteArray, int> StringToIdCache;
+Q_GLOBAL_STATIC(StringToIdCache, stringToIdCache)
+static int offset = sizeof(int);
+
+int insert_string_to_cache(const QByteArray &string);
+
+// fills our datastructures from memory
+// this method can be called several times to update the internal representation
+// if the cache has been changed by another application
+void fill_unique_string_cache() {
+ uchar *rawCache = uniqueStringCacheMappedMemory()->data();
+ int elementsInCache = *reinterpret_cast<int*>(rawCache);
+ int oldSize = idToStringCache()->count();
+ idToStringCache()->resize(elementsInCache);
+
+ for (int i = oldSize; i < elementsInCache; ++i) {
+ uchar *stringAdress = rawCache + offset;
+ int stringLength = *reinterpret_cast<int*>(stringAdress);
+ // TODO: figure out if we can delay creating the actual byte arrays. as long as stringForId()
+ // is not called we do not need to actually create them.
+ // first: check if this makes a difference at all
+ QByteArray string = QByteArray::fromRawData(reinterpret_cast<const char*>(stringAdress + sizeof(int)), stringLength);
+ offset += sizeof(int) + stringLength;
+
+ (*idToStringCache())[i] = string;
+ stringToIdCache()->insert(string, i);
+ }
+ if (elementsInCache == 0) {
+ // we want the empty string as first element
+ insert_string_to_cache(QByteArray());
+ }
+
+ qWarning() << "elements in cache:" << elementsInCache << ", " << (float)offset/MAX_CACHE_SIZE*100 << "% filled cache";
+}
+
+// insert one string into the cache, makes sure to handle it gracefully when the cache has
+// changed before it has been locked
+int insert_string_to_cache(const QByteArray &string) {
+ uchar *rawCache = uniqueStringCacheMappedMemory()->data();
+ int elementsInCache = *reinterpret_cast<int*>(rawCache);
+ if (elementsInCache != idToStringCache()->count()) {
+ // cache has changed, check if the string has been added
+ // in the meanwhile
+ fill_unique_string_cache();
+ StringToIdCache::const_iterator it = stringToIdCache()->constFind(string);
+ if (it != stringToIdCache()->constEnd()) {
+ return *it;
+ }
+ }
+
+ ++*reinterpret_cast<int*>(rawCache);
+
+ uchar *stringAdress = rawCache + offset;
+ *reinterpret_cast<int*>(stringAdress) = string.length();
+ memcpy(stringAdress + sizeof(int), string.constData(), string.length());
+
+ offset += sizeof(int) + string.length();
+ if (offset >= MAX_CACHE_SIZE) {
+ qFatal("unique string cache is full");
+ }
+
+ idToStringCache()->append(string);
+ stringToIdCache()->insert(string, idToStringCache()->count() - 1);
+
+ return idToStringCache()->count() - 1;
+}
+
+// triggers initialization of our data structures from the cache if this
+// did not happen yet
+void initially_fill_cache() {
+ static bool cacheFilled = false;
+ if (!cacheFilled) {
+ QElapsedTimer timer;
+ timer.start();
+ UniqueStringCacheMappedMemoryLocker locker(uniqueStringCacheMappedMemory());
+ if (!locker.isLocked()) {
+ return;
+ }
+ fill_unique_string_cache();
+
+ cacheFilled = true;
+ }
+}
+
+bool MUniqueStringCache::isAttached()
+{
+ UniqueStringCacheMappedMemoryLocker locker(uniqueStringCacheMappedMemory());
+ if (!locker.isLocked()) {
+ return false;
+ }
+ return uniqueStringCacheMappedMemory()->isAttached();
+}
+
+MUniqueStringCache::Index MUniqueStringCache::stringToIndex(const QByteArray& string)
+{
+ initially_fill_cache();
+ StringToIdCache::const_iterator it = stringToIdCache()->constFind(string);
+ if (it != stringToIdCache()->constEnd()) {
+ return *it;
+ }
+
+ // string is unknown, we need to add it to the cache
+ UniqueStringCacheMappedMemoryLocker locker(uniqueStringCacheMappedMemory());
+ if (!locker.isLocked()) {
+ return UndefinedIndex;
+ }
+
+ return insert_string_to_cache(string);
+}
+
+QByteArray MUniqueStringCache::indexToString(Index id)
+{
+ initially_fill_cache();
+ if (id < 0) {
+ return QByteArray();
+ } else if (id >= idToStringCache()->count()) {
+ mWarning("MUniqueStringCache::indexToString") << "Id" << id << "is unknown. Has the string cache been deleted?";
+ return QByteArray();
+ }
+
+ return idToStringCache()->at(id);
+}
diff --git a/src/corelib/style/muniquestringcache.h b/src/corelib/style/muniquestringcache.h
new file mode 100644
index 00000000..7a4349c7
--- /dev/null
+++ b/src/corelib/style/muniquestringcache.h
@@ -0,0 +1,37 @@
+/***************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (directui@nokia.com)
+**
+** This file is part of libmeegotouch.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at directui@nokia.com.
+**
+** This library is free software; you can redistribute it and/or
+** modify it under the terms of the GNU Lesser General Public
+** License version 2.1 as published by the Free Software Foundation
+** and appearing in the file LICENSE.LGPL included in the packaging
+** of this file.
+**
+****************************************************************************/
+
+#ifndef MUNIQUESTRINGCACHE_H
+#define MUNIQUESTRINGCACHE_H
+
+#include <QByteArray>
+
+class MUniqueStringCache
+{
+public:
+ typedef int Index;
+ static const Index UndefinedIndex = -1;
+ static const Index EmptyStringIndex = 0;
+
+ static bool isAttached();
+ static Index stringToIndex(const QByteArray& string);
+ static QByteArray indexToString(Index id);
+};
+
+#endif // MUNIQUESTRINGCACHE_H
diff --git a/src/corelib/style/style.pri b/src/corelib/style/style.pri
index 2b8ca2ee..93cb86b2 100644
--- a/src/corelib/style/style.pri
+++ b/src/corelib/style/style.pri
@@ -15,7 +15,8 @@ PRIVATE_HEADERS += \
$$STYLE_SRC_DIR/mstylesheetselector.h \
$$STYLE_SRC_DIR/mstylesheetattribute.h \
$$STYLE_SRC_DIR/mstylesheet.h \
- $$STYLE_SRC_DIR/mstylesheetselector_p.h
+ $$STYLE_SRC_DIR/mstylesheetselector_p.h \
+ $$STYLE_SRC_DIR/muniquestringcache.h
STYLE_HEADERS += \
$$STYLE_SRC_DIR/mstyle.h \
@@ -48,7 +49,7 @@ STYLE_HEADERS += \
$$STYLE_SRC_DIR/mcontentfadeandslideanimationstyle.h \
PUBLIC_HEADERS += \
- $$STYLE_HEADERS \
+ $$STYLE_HEADERS
SOURCES += \
$$STYLE_SRC_DIR/mstyle.cpp \
@@ -56,4 +57,6 @@ SOURCES += \
$$STYLE_SRC_DIR/mstylesheet.cpp \
$$STYLE_SRC_DIR/mstylesheetparser.cpp \
$$STYLE_SRC_DIR/mstylesheetselector.cpp \
- $$STYLE_SRC_DIR/mstylesheetattribute.cpp
+ $$STYLE_SRC_DIR/mstylesheetattribute.cpp \
+ $$STYLE_SRC_DIR/muniquestringcache.cpp \
+
diff --git a/tests/ft_mstylesheet/ft_mstylesheet.pro b/tests/ft_mstylesheet/ft_mstylesheet.pro
index 78f8a940..1207f2b6 100644
--- a/tests/ft_mstylesheet/ft_mstylesheet.pro
+++ b/tests/ft_mstylesheet/ft_mstylesheet.pro
@@ -11,7 +11,8 @@ STYLE_HEADERS += testobjectstyle.h testobject2style.h testobject3style.h
SOURCES += \
ft_mstylesheet.cpp \
$$MSRCDIR/corelib/theme/mlogicalvalues.cpp \
- $$MSRCDIR/corelib/style/mstylesheetattribute.cpp
+ $$MSRCDIR/corelib/style/mstylesheetattribute.cpp \
+ $$MSRCDIR/corelib/style/muniquestringcache.cpp
HEADERS += \
ft_mstylesheet.h \
@@ -23,6 +24,7 @@ HEADERS += \
testwidget3.h \
$$MSRCDIR/corelib/theme/mlogicalvalues.h \
$$MSRCDIR/corelib/style/mstylesheetattribute.h \
+ $$MSRCDIR/corelib/style/muniquestringcache.h \
$$STYLE_HEADERS
support_files.files += \
diff --git a/tests/ft_mstylesheetparser/ft_mstylesheetparser.cpp b/tests/ft_mstylesheetparser/ft_mstylesheetparser.cpp
index 154f7125..fff45d74 100644
--- a/tests/ft_mstylesheetparser/ft_mstylesheetparser.cpp
+++ b/tests/ft_mstylesheetparser/ft_mstylesheetparser.cpp
@@ -28,7 +28,7 @@
// include this to get theme profiling support
//#include "../../src/corelib/theme/mtheme_p.h"
-const int NUMBER_OF_LOOPS = 100;
+const int NUMBER_OF_LOOPS = 10000;
Ft_MStyleSheetParser::Ft_MStyleSheetParser()
: m_logicalValues(NULL),
@@ -444,50 +444,51 @@ void Ft_MStyleSheetParser::test_constants()
info = m_subject->fileInfoList()[1];
QCOMPARE(info->selectors.count(), 1);
QCOMPARE(info->selectors[0]->attributes()->count(), 1);
- info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-width"), NULL);
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-width"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-width"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-width"))->getValue(), QByteArray("10px"));
+ info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex("attr-width"), NULL);
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")))->getValue(), QByteArray("10px"));
info = m_subject->fileInfoList()[2];
QCOMPARE(info->selectors.count(), 1);
QCOMPARE(info->selectors[0]->attributes()->count(), 13);
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-int"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-int"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-int"))->getValue(), QByteArray("10"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1"))->getValue(), QByteArray("\"name\""));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2"))->getValue(), QByteArray("\"this is a string with constant \"name\"\" 10 1.0"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool"))->getValue(), QByteArray("true"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1"))->getValue(), QByteArray("10px 15px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2"))->getValue(), QByteArray("17px 11px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1"))->getValue(), QByteArray("sans 12px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2"))->getValue(), QByteArray("arial 10px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-color"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-color"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-color"))->getValue(), QByteArray("#0abba0"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid"))->getValue(), QByteArray(""));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-void"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-void"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-void"))->getValue(), QByteArray(""));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black"))->getValue(), QByteArray("#000000"));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green"))->getValue(), QByteArray("#00ff00"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")))->getValue(), QByteArray("10"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")));
+
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")))->getValue(), QByteArray("\"name\""));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")))->getValue(), QByteArray("\"this is a string with constant \"name\"\" 10 1.0"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")))->getValue(), QByteArray("true"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")))->getValue(), QByteArray("10px 15px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")))->getValue(), QByteArray("17px 11px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")))->getValue(), QByteArray("sans 12px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")))->getValue(), QByteArray("arial 10px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")))->getValue(), QByteArray("#0abba0"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")))->getValue(), QByteArray(""));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")))->getValue(), QByteArray(""));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")))->getValue(), QByteArray("#000000"));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")))->getValue(), QByteArray("#00ff00"));
}
void Ft_MStyleSheetParser::test_constants_binary()
@@ -513,49 +514,49 @@ void Ft_MStyleSheetParser::test_constants_binary()
info = m_subject->fileInfoList()[1];
QCOMPARE(info->selectors.count(), 1);
QCOMPARE(info->selectors[0]->attributes()->count(), 1);
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-width"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-width"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-width"))->getValue(), QByteArray("10px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-width")))->getValue(), QByteArray("10px"));
info = m_subject->fileInfoList()[2];
QCOMPARE(info->selectors.count(), 1);
QCOMPARE(info->selectors[0]->attributes()->count(), 13);
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-int"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-int"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-int"))->getValue(), QByteArray("10"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1"))->getValue(), QByteArray("\"name\""));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2"))->getValue(), QByteArray("\"this is a string with constant \"name\"\" 10 1.0"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool"))->getValue(), QByteArray("true"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1"))->getValue(), QByteArray("10px 15px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2"))->getValue(), QByteArray("17px 11px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1"))->getValue(), QByteArray("sans 12px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2"))->getValue(), QByteArray("arial 10px"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-color"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-color"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-color"))->getValue(), QByteArray("#0abba0"));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid"))->getValue(), QByteArray(""));
- QVERIFY(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-void"), NULL));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-void"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-void"))->getValue(), QByteArray(""));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black"))->getValue(), QByteArray("#000000"));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green"))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")));
- QCOMPARE(info->selectors[0]->attributes()->value(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green"))->getValue(), QByteArray("#00ff00"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-int")))->getValue(), QByteArray("10"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string1")))->getValue(), QByteArray("\"name\""));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-string2")))->getValue(), QByteArray("\"this is a string with constant \"name\"\" 10 1.0"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-bool")))->getValue(), QByteArray("true"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos1")))->getValue(), QByteArray("10px 15px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-pos2")))->getValue(), QByteArray("17px 11px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font1")))->getValue(), QByteArray("sans 12px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-font2")))->getValue(), QByteArray("arial 10px"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-color")))->getValue(), QByteArray("#0abba0"));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-invalid")))->getValue(), QByteArray(""));
+ QVERIFY(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")), NULL));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-void")))->getValue(), QByteArray(""));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-black")))->getValue(), QByteArray("#000000"));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")))->getName(), QByteArray(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")));
+ QCOMPARE(info->selectors[0]->attributes()->value(MUniqueStringCache::stringToIndex(MStyleSheetAttribute::attributeNameToPropertyName("attr-logical-green")))->getValue(), QByteArray("#00ff00"));
}
void Ft_MStyleSheetParser::test_binary_equality()
diff --git a/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro b/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro
index afe434f6..efcf1ff3 100644
--- a/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro
+++ b/tests/ft_mstylesheetparser/ft_mstylesheetparser.pro
@@ -8,13 +8,14 @@ INCLUDEPATH += $$MSRCDIR/corelib/core/
SOURCES += \
ft_mstylesheetparser.cpp \
$$MSRCDIR/corelib/theme/mlogicalvalues.cpp \
- $$MSRCDIR/corelib/style/mstylesheetattribute.cpp
-
+ $$MSRCDIR/corelib/style/muniquestringcache.cpp \
+ $$MSRCDIR/corelib/style/mstylesheetattribute.cpp \
HEADERS += \
ft_mstylesheetparser.h \
$$MSRCDIR/corelib/theme/mlogicalvalues.h \
- $$MSRCDIR/corelib/style/mstylesheetattribute.h
+ $$MSRCDIR/corelib/style/muniquestringcache.h \
+ $$MSRCDIR/corelib/style/mstylesheetattribute.h \
support_files.files += \
*.css \
diff --git a/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro b/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro
index a47f1440..a8366e99 100644
--- a/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro
+++ b/tests/ut_mlogicalvalues/ut_mlogicalvalues.pro
@@ -8,13 +8,16 @@ INCLUDEPATH += $$MSRCDIR/corelib/core/
SOURCES += \
ut_mlogicalvalues.cpp \
$$MSRCDIR/corelib/theme/mlogicalvalues.cpp \
- $$MSRCDIR/corelib/style/mstylesheetattribute.cpp
+ $$MSRCDIR/corelib/style/mstylesheetattribute.cpp \
+ $$MSRCDIR/corelib/style/muniquestringcache.cpp
HEADERS += \
ut_mlogicalvalues.h \
$$MSRCDIR/corelib/theme/mlogicalvalues.h \
$$MSRCDIR/corelib/theme/mlogicalvalues_p.h \
- $$MSRCDIR/corelib/style/mstylesheetattribute.h
+ $$MSRCDIR/corelib/style/mstylesheetattribute.h \
+ $$MSRCDIR/corelib/style/muniquestringcache.h
+
support_files.files += *.ini