diff options
author | Lars Knoll <lars.knoll@digia.com> | 2014-01-24 22:11:16 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-01-31 11:13:48 +0100 |
commit | 28f422ebf516aefb34f1602aeef8f87432cc4fb9 (patch) | |
tree | 40aa271711eb4f3c6791d4666ec210069e1b4fce /src/qml/jsruntime/qv4arraydata.cpp | |
parent | e37a9eb4a47eb3e5cb9f4dedccec6b69e8509625 (diff) |
Move ArrayElementLessThen to qv4arraydata.cpp
This is the only place the class gets used.
Change-Id: Iebb0cba7af30c1b2da68f67596c349d5e20c5053
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
Diffstat (limited to 'src/qml/jsruntime/qv4arraydata.cpp')
-rw-r--r-- | src/qml/jsruntime/qv4arraydata.cpp | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/src/qml/jsruntime/qv4arraydata.cpp b/src/qml/jsruntime/qv4arraydata.cpp index 9c6ff94583..63fe650cd5 100644 --- a/src/qml/jsruntime/qv4arraydata.cpp +++ b/src/qml/jsruntime/qv4arraydata.cpp @@ -630,6 +630,47 @@ Property *ArrayData::insert(Object *o, uint index, bool isAccessor) return reinterpret_cast<Property *>(o->arrayData->data + n->value); } + +class ArrayElementLessThan +{ +public: + inline ArrayElementLessThan(ExecutionContext *context, ObjectRef thisObject, const ValueRef comparefn) + : m_context(context), thisObject(thisObject), m_comparefn(comparefn) {} + + bool operator()(const SafeValue &v1, const SafeValue &v2) const; + +private: + ExecutionContext *m_context; + ObjectRef thisObject; + const ValueRef m_comparefn; +}; + + +bool ArrayElementLessThan::operator()(const SafeValue &v1, const SafeValue &v2) const +{ + Scope scope(m_context); + + if (v1.isUndefined() || v1.isEmpty()) + return false; + if (v2.isUndefined() || v2.isEmpty()) + return true; + ScopedObject o(scope, m_comparefn); + if (o) { + Scope scope(o->engine()); + ScopedValue result(scope); + ScopedCallData callData(scope, 2); + callData->thisObject = Primitive::undefinedValue(); + callData->args[0] = v1; + callData->args[1] = v2; + result = __qmljs_call_value(m_context, m_comparefn, callData); + + return result->toNumber() < 0; + } + ScopedString p1s(scope, v1.toString(m_context)); + ScopedString p2s(scope, v2.toString(m_context)); + return p1s->toQString() < p2s->toQString(); +} + void ArrayData::sort(ExecutionContext *context, ObjectRef thisObject, const ValueRef comparefn, uint len) { if (!len) |