Convert StringObject to new storage layout
Change-Id: I08251049fed92306e1acfd8926ffad270d2e3ca7 Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
This commit is contained in:
parent
541da47975
commit
03cef66854
|
@ -735,7 +735,7 @@ QString Stringify::Str(const QString &key, ValueRef v)
|
|||
if (NumberObject *n = o->asNumberObject())
|
||||
value = n->value();
|
||||
else if (StringObject *so = o->asStringObject())
|
||||
value = so->value;
|
||||
value = so->d()->value;
|
||||
else if (BooleanObject *b =o->asBooleanObject())
|
||||
value = b->value();
|
||||
}
|
||||
|
@ -941,7 +941,7 @@ ReturnedValue JsonObject::method_stringify(CallContext *ctx)
|
|||
if (NumberObject *n = s->asNumberObject())
|
||||
s = n->value();
|
||||
else if (StringObject *so = s->asStringObject())
|
||||
s = so->value;
|
||||
s = so->d()->value;
|
||||
|
||||
if (s->isNumber()) {
|
||||
stringify.gap = QString(qMin(10, (int)s->toInteger()), ' ');
|
||||
|
|
|
@ -374,7 +374,7 @@ bool Object::hasOwnProperty(uint index) const
|
|||
if (!arrayData()->isEmpty(index))
|
||||
return true;
|
||||
if (isStringObject()) {
|
||||
String *s = static_cast<const StringObject *>(this)->value.asString();
|
||||
String *s = static_cast<const StringObject *>(this)->d()->value.asString();
|
||||
if (index < (uint)s->length())
|
||||
return true;
|
||||
}
|
||||
|
@ -434,7 +434,7 @@ PropertyAttributes Object::queryIndexed(const Managed *m, uint index)
|
|||
return o->arrayData()->attributes(index);
|
||||
|
||||
if (o->isStringObject()) {
|
||||
String *s = static_cast<const StringObject *>(o)->value.asString();
|
||||
String *s = static_cast<const StringObject *>(o)->d()->value.asString();
|
||||
if (index < (uint)s->length())
|
||||
return (Attr_NotWritable|Attr_NotConfigurable);
|
||||
}
|
||||
|
|
|
@ -85,9 +85,9 @@ StringObject::StringObject(InternalClass *ic)
|
|||
Scope scope(engine());
|
||||
ScopedObject protectThis(scope, this);
|
||||
|
||||
value = ic->engine->newString(QStringLiteral(""))->asReturnedValue();
|
||||
d()->value = ic->engine->newString(QStringLiteral(""))->asReturnedValue();
|
||||
|
||||
tmpProperty.value = Primitive::undefinedValue();
|
||||
d()->tmpProperty.value = Primitive::undefinedValue();
|
||||
|
||||
defineReadonlyProperty(ic->engine->id_length, Primitive::fromInt32(0));
|
||||
}
|
||||
|
@ -100,21 +100,21 @@ StringObject::StringObject(ExecutionEngine *engine, const ValueRef val)
|
|||
Scope scope(engine);
|
||||
ScopedObject protectThis(scope, this);
|
||||
|
||||
value = *val;
|
||||
d()->value = *val;
|
||||
|
||||
tmpProperty.value = Primitive::undefinedValue();
|
||||
d()->tmpProperty.value = Primitive::undefinedValue();
|
||||
|
||||
assert(value.isString());
|
||||
defineReadonlyProperty(engine->id_length, Primitive::fromUInt32(value.stringValue()->toQString().length()));
|
||||
assert(d()->value.isString());
|
||||
defineReadonlyProperty(engine->id_length, Primitive::fromUInt32(d()->value.stringValue()->toQString().length()));
|
||||
}
|
||||
|
||||
Property *StringObject::getIndex(uint index) const
|
||||
{
|
||||
QString str = value.stringValue()->toQString();
|
||||
QString str = d()->value.stringValue()->toQString();
|
||||
if (index >= (uint)str.length())
|
||||
return 0;
|
||||
tmpProperty.value = Encode(internalClass()->engine->newString(str.mid(index, 1)));
|
||||
return &tmpProperty;
|
||||
d()->tmpProperty.value = Encode(internalClass()->engine->newString(str.mid(index, 1)));
|
||||
return &d()->tmpProperty;
|
||||
}
|
||||
|
||||
bool StringObject::deleteIndexedProperty(Managed *m, uint index)
|
||||
|
@ -127,7 +127,7 @@ bool StringObject::deleteIndexedProperty(Managed *m, uint index)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (index < static_cast<uint>(o->value.stringValue()->toQString().length())) {
|
||||
if (index < static_cast<uint>(o->d()->value.stringValue()->toQString().length())) {
|
||||
if (v4->currentContext()->strictMode)
|
||||
v4->currentContext()->throwTypeError();
|
||||
return false;
|
||||
|
@ -139,7 +139,7 @@ void StringObject::advanceIterator(Managed *m, ObjectIterator *it, StringRef nam
|
|||
{
|
||||
name = (String *)0;
|
||||
StringObject *s = static_cast<StringObject *>(m);
|
||||
uint slen = s->value.stringValue()->toQString().length();
|
||||
uint slen = s->d()->value.stringValue()->toQString().length();
|
||||
if (it->arrayIndex <= slen) {
|
||||
while (it->arrayIndex < slen) {
|
||||
*index = it->arrayIndex;
|
||||
|
@ -166,8 +166,8 @@ void StringObject::advanceIterator(Managed *m, ObjectIterator *it, StringRef nam
|
|||
void StringObject::markObjects(Managed *that, ExecutionEngine *e)
|
||||
{
|
||||
StringObject *o = static_cast<StringObject *>(that);
|
||||
o->value.stringValue()->mark(e);
|
||||
o->tmpProperty.value.mark(e);
|
||||
o->d()->value.stringValue()->mark(e);
|
||||
o->d()->tmpProperty.value.mark(e);
|
||||
Object::markObjects(that, e);
|
||||
}
|
||||
|
||||
|
@ -242,7 +242,7 @@ static QString getThisString(ExecutionContext *ctx)
|
|||
if (t->isString())
|
||||
return t->stringValue()->toQString();
|
||||
if (StringObject *thisString = t->asStringObject())
|
||||
return thisString->value.stringValue()->toQString();
|
||||
return thisString->d()->value.stringValue()->toQString();
|
||||
if (t->isUndefined() || t->isNull()) {
|
||||
ctx->throwTypeError();
|
||||
return QString();
|
||||
|
@ -258,7 +258,7 @@ ReturnedValue StringPrototype::method_toString(CallContext *context)
|
|||
StringObject *o = context->callData->thisObject.asStringObject();
|
||||
if (!o)
|
||||
return context->throwTypeError();
|
||||
return o->value.asReturnedValue();
|
||||
return o->d()->value.asReturnedValue();
|
||||
}
|
||||
|
||||
ReturnedValue StringPrototype::method_charAt(CallContext *context)
|
||||
|
@ -492,7 +492,7 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx)
|
|||
Scope scope(ctx);
|
||||
QString string;
|
||||
if (StringObject *thisString = ctx->callData->thisObject.asStringObject())
|
||||
string = thisString->value.stringValue()->toQString();
|
||||
string = thisString->d()->value.stringValue()->toQString();
|
||||
else
|
||||
string = ctx->callData->thisObject.toString(ctx)->toQString();
|
||||
|
||||
|
@ -526,7 +526,7 @@ ReturnedValue StringPrototype::method_replace(CallContext *ctx)
|
|||
break;
|
||||
}
|
||||
nMatchOffsets += re->captureCount() * 2;
|
||||
if (!regExp->global)
|
||||
if (!regExp->d()->global)
|
||||
break;
|
||||
offset = qMax(offset + 1, matchOffsets[oldSize + 1]);
|
||||
}
|
||||
|
|
|
@ -50,11 +50,18 @@ QT_BEGIN_NAMESPACE
|
|||
namespace QV4 {
|
||||
|
||||
struct StringObject: Object {
|
||||
V4_OBJECT
|
||||
Q_MANAGED_TYPE(StringObject)
|
||||
|
||||
struct Data : Object::Data {
|
||||
Value value;
|
||||
// ### get rid of tmpProperty
|
||||
mutable Property tmpProperty;
|
||||
};
|
||||
struct {
|
||||
Value value;
|
||||
mutable Property tmpProperty;
|
||||
} __data;
|
||||
V4_OBJECT_NEW
|
||||
Q_MANAGED_TYPE(StringObject)
|
||||
|
||||
StringObject(ExecutionEngine *engine, const ValueRef value);
|
||||
|
||||
Property *getIndex(uint index) const;
|
||||
|
@ -69,7 +76,7 @@ protected:
|
|||
|
||||
struct StringCtor: FunctionObject
|
||||
{
|
||||
V4_OBJECT
|
||||
V4_OBJECT_NEW
|
||||
StringCtor(ExecutionContext *scope);
|
||||
|
||||
static ReturnedValue construct(Managed *m, CallData *callData);
|
||||
|
|
Loading…
Reference in New Issue