aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/qml/jsruntime/qv4identifier.cpp4
-rw-r--r--src/qml/jsruntime/qv4identifiertable.cpp32
-rw-r--r--src/qml/jsruntime/qv4identifiertable_p.h4
-rw-r--r--src/qml/jsruntime/qv4internalclass.cpp12
-rw-r--r--src/qml/jsruntime/qv4string.cpp88
-rw-r--r--src/qml/jsruntime/qv4string_p.h86
6 files changed, 117 insertions, 109 deletions
diff --git a/src/qml/jsruntime/qv4identifier.cpp b/src/qml/jsruntime/qv4identifier.cpp
index b78020ed13..bbb756bab3 100644
--- a/src/qml/jsruntime/qv4identifier.cpp
+++ b/src/qml/jsruntime/qv4identifier.cpp
@@ -149,8 +149,8 @@ const IdentifierHashEntry *IdentifierHashBase::lookup(String *str) const
{
if (!d)
return 0;
- if (str->stringData()->identifier)
- return lookup(str->stringData()->identifier);
+ if (str->d()->identifier)
+ return lookup(str->d()->identifier);
return lookup(str->toQString());
}
diff --git a/src/qml/jsruntime/qv4identifiertable.cpp b/src/qml/jsruntime/qv4identifiertable.cpp
index 2d127af0e6..8627438fe1 100644
--- a/src/qml/jsruntime/qv4identifiertable.cpp
+++ b/src/qml/jsruntime/qv4identifiertable.cpp
@@ -69,7 +69,7 @@ IdentifierTable::~IdentifierTable()
{
for (int i = 0; i < alloc; ++i)
if (entries[i])
- delete entries[i]->stringData()->identifier;
+ delete entries[i]->d()->identifier;
free(entries);
}
@@ -80,9 +80,9 @@ void IdentifierTable::addEntry(String *str)
if (str->subtype() == String::StringType_ArrayIndex)
return;
- str->stringData()->identifier = new Identifier;
- str->stringData()->identifier->string = str->toQString();
- str->stringData()->identifier->hashValue = hash;
+ str->d()->identifier = new Identifier;
+ str->d()->identifier->string = str->toQString();
+ str->d()->identifier->hashValue = hash;
bool grow = (alloc <= size*2);
@@ -95,7 +95,7 @@ void IdentifierTable::addEntry(String *str)
String *e = entries[i];
if (!e)
continue;
- uint idx = e->stringData()->stringHash % newAlloc;
+ uint idx = e->d()->stringHash % newAlloc;
while (newEntries[idx]) {
++idx;
idx %= newAlloc;
@@ -123,7 +123,7 @@ String *IdentifierTable::insertString(const QString &s)
uint hash = String::createHashValue(s.constData(), s.length());
uint idx = hash % alloc;
while (String *e = entries[idx]) {
- if (e->stringData()->stringHash == hash && e->toQString() == s)
+ if (e->d()->stringHash == hash && e->toQString() == s)
return e;
++idx;
idx %= alloc;
@@ -137,29 +137,29 @@ String *IdentifierTable::insertString(const QString &s)
Identifier *IdentifierTable::identifierImpl(const String *str)
{
- if (str->stringData()->identifier)
- return str->stringData()->identifier;
+ if (str->d()->identifier)
+ return str->d()->identifier;
uint hash = str->hashValue();
if (str->subtype() == String::StringType_ArrayIndex)
return 0;
uint idx = hash % alloc;
while (String *e = entries[idx]) {
- if (e->stringData()->stringHash == hash && e->isEqualTo(str)) {
- str->stringData()->identifier = e->stringData()->identifier;
- return e->stringData()->identifier;
+ if (e->d()->stringHash == hash && e->isEqualTo(str)) {
+ str->d()->identifier = e->d()->identifier;
+ return e->d()->identifier;
}
++idx;
idx %= alloc;
}
addEntry(const_cast<QV4::String *>(str));
- return str->stringData()->identifier;
+ return str->d()->identifier;
}
Identifier *IdentifierTable::identifier(const QString &s)
{
- return insertString(s)->stringData()->identifier;
+ return insertString(s)->d()->identifier;
}
Identifier *IdentifierTable::identifier(const char *s, int len)
@@ -171,15 +171,15 @@ Identifier *IdentifierTable::identifier(const char *s, int len)
QLatin1String latin(s, len);
uint idx = hash % alloc;
while (String *e = entries[idx]) {
- if (e->stringData()->stringHash == hash && e->toQString() == latin)
- return e->stringData()->identifier;
+ if (e->d()->stringHash == hash && e->toQString() == latin)
+ return e->d()->identifier;
++idx;
idx %= alloc;
}
String *str = engine->newString(QString::fromLatin1(s, len))->getPointer();
addEntry(str);
- return str->stringData()->identifier;
+ return str->d()->identifier;
}
}
diff --git a/src/qml/jsruntime/qv4identifiertable_p.h b/src/qml/jsruntime/qv4identifiertable_p.h
index 249a45811d..eb29f84af5 100644
--- a/src/qml/jsruntime/qv4identifiertable_p.h
+++ b/src/qml/jsruntime/qv4identifiertable_p.h
@@ -69,8 +69,8 @@ public:
String *insertString(const QString &s);
Identifier *identifier(const String *str) {
- if (str->stringData()->identifier)
- return str->stringData()->identifier;
+ if (str->d()->identifier)
+ return str->d()->identifier;
return identifierImpl(str);
}
diff --git a/src/qml/jsruntime/qv4internalclass.cpp b/src/qml/jsruntime/qv4internalclass.cpp
index 354bedd311..35efd3c022 100644
--- a/src/qml/jsruntime/qv4internalclass.cpp
+++ b/src/qml/jsruntime/qv4internalclass.cpp
@@ -181,7 +181,7 @@ InternalClass *InternalClass::changeMember(String *string, PropertyAttributes da
if (data == propertyData.at(idx))
return this;
- Transition t = { { string->stringData()->identifier }, (int)data.flags() };
+ Transition t = { { string->d()->identifier }, (int)data.flags() };
QHash<Transition, InternalClass *>::const_iterator tit = transitions.constFind(t);
if (tit != transitions.constEnd())
return tit.value();
@@ -280,7 +280,7 @@ void InternalClass::addMember(Object *object, String *string, PropertyAttributes
{
data.resolve();
object->internalClass()->engine->identifierTable->identifier(string);
- if (object->internalClass()->propertyTable.lookup(string->stringData()->identifier) < object->internalClass()->size) {
+ if (object->internalClass()->propertyTable.lookup(string->d()->identifier) < object->internalClass()->size) {
changeMember(object, string, data, index);
return;
}
@@ -304,7 +304,7 @@ InternalClass *InternalClass::addMember(String *string, PropertyAttributes data,
data.resolve();
engine->identifierTable->identifier(string);
- if (propertyTable.lookup(string->stringData()->identifier) < size)
+ if (propertyTable.lookup(string->d()->identifier) < size)
return changeMember(string, data, index);
return addMemberImpl(string, data, index);
@@ -312,7 +312,7 @@ InternalClass *InternalClass::addMember(String *string, PropertyAttributes data,
InternalClass *InternalClass::addMemberImpl(String *string, PropertyAttributes data, uint *index)
{
- Transition t = { { string->stringData()->identifier }, (int)data.flags() };
+ Transition t = { { string->d()->identifier }, (int)data.flags() };
QHash<Transition, InternalClass *>::const_iterator tit = transitions.constFind(t);
if (index)
@@ -322,7 +322,7 @@ InternalClass *InternalClass::addMemberImpl(String *string, PropertyAttributes d
// create a new class and add it to the tree
InternalClass *newClass = engine->newClass(*this);
- PropertyHash::Entry e = { string->stringData()->identifier, newClass->size };
+ PropertyHash::Entry e = { string->d()->identifier, newClass->size };
newClass->propertyTable.addEntry(e, newClass->size);
// The incoming string can come from anywhere, so make sure to
@@ -382,7 +382,7 @@ uint InternalClass::find(const StringRef string)
uint InternalClass::find(const String *string)
{
engine->identifierTable->identifier(string);
- const Identifier *id = string->stringData()->identifier;
+ const Identifier *id = string->d()->identifier;
uint index = propertyTable.lookup(id);
if (index < size)
diff --git a/src/qml/jsruntime/qv4string.cpp b/src/qml/jsruntime/qv4string.cpp
index 5c21548173..f489699b2a 100644
--- a/src/qml/jsruntime/qv4string.cpp
+++ b/src/qml/jsruntime/qv4string.cpp
@@ -133,9 +133,9 @@ void String::destroy(Managed *that)
void String::markObjects(Managed *that, ExecutionEngine *e)
{
String *s = static_cast<String *>(that);
- if (s->stringData()->largestSubLength) {
- s->stringData()->left->mark(e);
- s->stringData()->right->mark(e);
+ if (s->d()->largestSubLength) {
+ s->d()->left->mark(e);
+ s->d()->right->mark(e);
}
}
@@ -148,7 +148,7 @@ ReturnedValue String::get(Managed *m, const StringRef name, bool *hasProperty)
if (name->equals(v4->id_length)) {
if (hasProperty)
*hasProperty = true;
- return Primitive::fromInt32(that->stringData()->text->size).asReturnedValue();
+ return Primitive::fromInt32(that->d()->text->size).asReturnedValue();
}
PropertyAttributes attrs;
Property *pd = v4->stringObjectClass->prototype->__getPropertyDescriptor__(name, &attrs);
@@ -168,7 +168,7 @@ ReturnedValue String::getIndexed(Managed *m, uint index, bool *hasProperty)
Scope scope(engine);
ScopedString that(scope, static_cast<String *>(m));
- if (index < static_cast<uint>(that->stringData()->text->size)) {
+ if (index < static_cast<uint>(that->d()->text->size)) {
if (hasProperty)
*hasProperty = true;
return Encode(engine->newString(that->toQString().mid(index, 1)));
@@ -217,7 +217,7 @@ PropertyAttributes String::query(const Managed *m, StringRef name)
PropertyAttributes String::queryIndexed(const Managed *m, uint index)
{
const String *that = static_cast<const String *>(m);
- return (index < static_cast<uint>(that->stringData()->text->size)) ? Attr_NotConfigurable|Attr_NotWritable : Attr_Invalid;
+ return (index < static_cast<uint>(that->d()->text->size)) ? Attr_NotConfigurable|Attr_NotWritable : Attr_Invalid;
}
bool String::deleteProperty(Managed *, const StringRef)
@@ -254,13 +254,13 @@ bool String::isEqualTo(Managed *t, Managed *o)
String::String(ExecutionEngine *engine, const QString &text)
: Managed(engine->stringClass)
{
- Data *d = stringData();
- d->text = const_cast<QString &>(text).data_ptr();
- d->text->ref.ref();
- d->identifier = 0;
- d->stringHash = UINT_MAX;
- d->largestSubLength = 0;
- d->len = stringData()->text->size;
+ Data *data = d();
+ data->text = const_cast<QString &>(text).data_ptr();
+ data->text->ref.ref();
+ data->identifier = 0;
+ data->stringHash = UINT_MAX;
+ data->largestSubLength = 0;
+ data->len = d()->text->size;
setSubtype(StringType_Unknown);
}
@@ -269,20 +269,20 @@ String::String(ExecutionEngine *engine, String *l, String *r)
{
setSubtype(StringType_Unknown);
- Data *d = stringData();
- d->left = l;
- d->right = r;
- d->stringHash = UINT_MAX;
- d->largestSubLength = qMax(l->stringData()->largestSubLength, r->stringData()->largestSubLength);
- d->len = l->stringData()->len + r->stringData()->len;
+ Data *data = d();
+ data->left = l;
+ data->right = r;
+ data->stringHash = UINT_MAX;
+ data->largestSubLength = qMax(l->d()->largestSubLength, r->d()->largestSubLength);
+ data->len = l->d()->len + r->d()->len;
- if (!l->stringData()->largestSubLength && l->stringData()->len > stringData()->largestSubLength)
- stringData()->largestSubLength = l->stringData()->len;
- if (!r->stringData()->largestSubLength && r->stringData()->len > stringData()->largestSubLength)
- stringData()->largestSubLength = r->stringData()->len;
+ if (!l->d()->largestSubLength && l->d()->len > d()->largestSubLength)
+ d()->largestSubLength = l->d()->len;
+ if (!r->d()->largestSubLength && r->d()->len > d()->largestSubLength)
+ d()->largestSubLength = r->d()->len;
// make sure we don't get excessive depth in our strings
- if (stringData()->len > 256 && stringData()->len >= 2*stringData()->largestSubLength)
+ if (d()->len > 256 && d()->len >= 2*d()->largestSubLength)
simplifyString();
}
@@ -293,7 +293,7 @@ uint String::toUInt(bool *ok) const
if (subtype() == StringType_Unknown)
createHashValue();
if (subtype() >= StringType_UInt)
- return stringData()->stringHash;
+ return d()->stringHash;
// ### this conversion shouldn't be required
double d = RuntimeHelpers::stringToNumber(toQString());
@@ -320,34 +320,34 @@ bool String::equals(const StringRef other) const
void String::makeIdentifierImpl() const
{
- if (stringData()->largestSubLength)
+ if (d()->largestSubLength)
simplifyString();
- Q_ASSERT(!stringData()->largestSubLength);
+ Q_ASSERT(!d()->largestSubLength);
engine()->identifierTable->identifier(this);
}
void String::simplifyString() const
{
- Q_ASSERT(stringData()->largestSubLength);
+ Q_ASSERT(d()->largestSubLength);
int l = length();
QString result(l, Qt::Uninitialized);
QChar *ch = const_cast<QChar *>(result.constData());
recursiveAppend(ch);
- stringData()->text = result.data_ptr();
- stringData()->text->ref.ref();
- stringData()->identifier = 0;
- stringData()->largestSubLength = 0;
+ d()->text = result.data_ptr();
+ d()->text->ref.ref();
+ d()->identifier = 0;
+ d()->largestSubLength = 0;
}
QChar *String::recursiveAppend(QChar *ch) const
{
- if (stringData()->largestSubLength) {
- ch = stringData()->left->recursiveAppend(ch);
- ch = stringData()->right->recursiveAppend(ch);
+ if (d()->largestSubLength) {
+ ch = d()->left->recursiveAppend(ch);
+ ch = d()->right->recursiveAppend(ch);
} else {
- memcpy(ch, stringData()->text->data(), stringData()->text->size*sizeof(QChar));
- ch += stringData()->text->size;
+ memcpy(ch, d()->text->data(), d()->text->size*sizeof(QChar));
+ ch += d()->text->size;
}
return ch;
}
@@ -355,17 +355,17 @@ QChar *String::recursiveAppend(QChar *ch) const
void String::createHashValue() const
{
- if (stringData()->largestSubLength)
+ if (d()->largestSubLength)
simplifyString();
- Q_ASSERT(!stringData()->largestSubLength);
- const QChar *ch = reinterpret_cast<const QChar *>(stringData()->text->data());
- const QChar *end = ch + stringData()->text->size;
+ Q_ASSERT(!d()->largestSubLength);
+ const QChar *ch = reinterpret_cast<const QChar *>(d()->text->data());
+ const QChar *end = ch + d()->text->size;
// array indices get their number as hash value
bool ok;
- stringData()->stringHash = ::toArrayIndex(ch, end, &ok);
+ d()->stringHash = ::toArrayIndex(ch, end, &ok);
if (ok) {
- setSubtype((stringData()->stringHash == UINT_MAX) ? StringType_UInt : StringType_ArrayIndex);
+ setSubtype((d()->stringHash == UINT_MAX) ? StringType_UInt : StringType_ArrayIndex);
return;
}
@@ -375,7 +375,7 @@ void String::createHashValue() const
++ch;
}
- stringData()->stringHash = h;
+ d()->stringHash = h;
setSubtype(StringType_Regular);
}
diff --git a/src/qml/jsruntime/qv4string_p.h b/src/qml/jsruntime/qv4string_p.h
index 615be29496..9a74136f6a 100644
--- a/src/qml/jsruntime/qv4string_p.h
+++ b/src/qml/jsruntime/qv4string_p.h
@@ -53,8 +53,34 @@ struct Identifier;
struct Q_QML_PRIVATE_EXPORT String : public Managed {
#ifndef V4_BOOTSTRAP
+ struct Data : Managed::Data {
+ union {
+ mutable QStringData *text;
+ mutable String *left;
+ };
+ union {
+ mutable Identifier *identifier;
+ mutable String *right;
+ };
+ mutable uint stringHash;
+ mutable uint largestSubLength;
+ uint len;
+ };
+ struct {
+ union {
+ mutable QStringData *text;
+ mutable String *left;
+ };
+ union {
+ mutable Identifier *identifier;
+ mutable String *right;
+ };
+ mutable uint stringHash;
+ mutable uint largestSubLength;
+ uint len;
+ } __data;
// ### FIXME: Should this be a V4_OBJECT
- V4_OBJECT
+ V4_OBJECT_NEW
Q_MANAGED_TYPE(String)
enum {
IsString = true
@@ -70,8 +96,8 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
String(ExecutionEngine *engine, const QString &text);
String(ExecutionEngine *engine, String *l, String *n);
~String() {
- if (!stringData()->largestSubLength && !stringData()->text->ref.deref())
- QStringData::deallocate(stringData()->text);
+ if (!d()->largestSubLength && !d()->text->ref.deref())
+ QStringData::deallocate(d()->text);
}
bool equals(const StringRef other) const;
@@ -80,8 +106,8 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
return true;
if (hashValue() != other->hashValue())
return false;
- Q_ASSERT(!stringData()->largestSubLength);
- if (stringData()->identifier && stringData()->identifier == other->stringData()->identifier)
+ Q_ASSERT(!d()->largestSubLength);
+ if (d()->identifier && d()->identifier == other->d()->identifier)
return true;
if (subtype() >= StringType_UInt && subtype() == other->subtype())
return true;
@@ -94,10 +120,10 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
}
inline QString toQString() const {
- if (stringData()->largestSubLength)
+ if (d()->largestSubLength)
simplifyString();
- QStringDataPtr ptr = { stringData()->text };
- stringData()->text->ref.ref();
+ QStringDataPtr ptr = { d()->text };
+ d()->text->ref.ref();
return QString(ptr);
}
@@ -106,22 +132,22 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
inline unsigned hashValue() const {
if (subtype() == StringType_Unknown)
createHashValue();
- Q_ASSERT(!stringData()->largestSubLength);
+ Q_ASSERT(!d()->largestSubLength);
- return stringData()->stringHash;
+ return d()->stringHash;
}
uint asArrayIndex() const {
if (subtype() == StringType_Unknown)
createHashValue();
- Q_ASSERT(!stringData()->largestSubLength);
+ Q_ASSERT(!d()->largestSubLength);
if (subtype() == StringType_ArrayIndex)
- return stringData()->stringHash;
+ return d()->stringHash;
return UINT_MAX;
}
uint toUInt(bool *ok) const;
void makeIdentifier() const {
- if (stringData()->identifier)
+ if (d()->identifier)
return;
makeIdentifierImpl();
}
@@ -134,36 +160,18 @@ struct Q_QML_PRIVATE_EXPORT String : public Managed {
bool startsWithUpper() const {
const String *l = this;
- while (l->stringData()->largestSubLength)
- l = l->stringData()->left;
- return l->stringData()->text->size && QChar::isUpper(l->stringData()->text->data()[0]);
+ while (l->d()->largestSubLength)
+ l = l->d()->left;
+ return l->d()->text->size && QChar::isUpper(l->d()->text->data()[0]);
}
int length() const {
- Q_ASSERT((stringData()->largestSubLength &&
- (stringData()->len == stringData()->left->stringData()->len + stringData()->right->stringData()->len)) ||
- stringData()->len == (uint)stringData()->text->size);
- return stringData()->len;
+ Q_ASSERT((d()->largestSubLength &&
+ (d()->len == d()->left->d()->len + d()->right->d()->len)) ||
+ d()->len == (uint)d()->text->size);
+ return d()->len;
}
- struct Data {
- union {
- mutable QStringData *text;
- mutable String *left;
- };
- union {
- mutable Identifier *identifier;
- mutable String *right;
- };
- mutable uint stringHash;
- mutable uint largestSubLength;
- uint len;
- };
- Data data;
-
- const Data *stringData() const { return &data; }
- Data *stringData() { return &data; }
-
- Identifier *identifier() const { return stringData()->identifier; }
+ Identifier *identifier() const { return d()->identifier; }
protected:
static void destroy(Managed *);