From 9969d6f3099bd0fc19668754a5d54c740c5e7fd8 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 10 Jun 2013 15:10:02 +0200 Subject: [PATCH] Remove two more places where we used v8 Change Value::isInt32() to convert to an integer if possible. Use this to avoid casting doubles to ints twice. usage of v8::Value::IsInt32() in two places. Change-Id: I5b9d8be7d90b461c11440bf54660ceef7e8f0f1b Reviewed-by: Simon Hausmann --- src/qml/qml/v4/qv4value_p.h | 12 +++++++++--- src/qml/qml/v4/qv4variantobject.cpp | 5 +++-- src/quick/items/qquickdrag.cpp | 6 +++--- src/quick/items/qquickdroparea.cpp | 6 +++--- 4 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/qml/qml/v4/qv4value_p.h b/src/qml/qml/v4/qv4value_p.h index 207ee22..cc27954 100644 --- a/src/qml/qml/v4/qv4value_p.h +++ b/src/qml/qml/v4/qv4value_p.h @@ -151,11 +151,17 @@ struct Q_QML_EXPORT Value inline bool isObject() const { return tag == Object_Type; } #endif inline bool isConvertibleToInt() const { return (tag & ConvertibleToInt) == ConvertibleToInt; } - inline bool isInt32() const { + inline bool isInt32() { if (tag == _Integer_Type) return true; - if (isDouble() && (int)dbl == dbl) - return true; + if (isDouble()) { + int i = (int)dbl; + if (i == dbl) { + int_32 = i; + tag = _Integer_Type; + return true; + } + } return false; } diff --git a/src/qml/qml/v4/qv4variantobject.cpp b/src/qml/qml/v4/qv4variantobject.cpp index ddd6002..733f289 100644 --- a/src/qml/qml/v4/qv4variantobject.cpp +++ b/src/qml/qml/v4/qv4variantobject.cpp @@ -72,8 +72,9 @@ QVariant VariantObject::toVariant(const QV4::Value &v) if (v.isBoolean()) return QVariant(v.booleanValue()); if (v.isNumber()) { - if (v.isInt32()) - return QVariant(v.toInt32()); + QV4::Value val = v; + if (val.isInt32()) + return QVariant(val.integerValue()); return QVariant(v.asDouble()); } if (v.isNull()) diff --git a/src/quick/items/qquickdrag.cpp b/src/quick/items/qquickdrag.cpp index 14bd4b5..55b3e56 100644 --- a/src/quick/items/qquickdrag.cpp +++ b/src/quick/items/qquickdrag.cpp @@ -517,9 +517,9 @@ void QQuickDragAttached::start(QQmlV4Function *args) Qt::DropActions supportedActions = d->supportedActions; // check arguments for supportedActions, maybe data? if (args->length() >= 1) { - v8::Handle v = (*args)[0]; - if (v->IsInt32()) { - supportedActions = Qt::DropActions(v->Int32Value()); + QV4::Value v = (*args)[0]; + if (v.isInt32()) { + supportedActions = Qt::DropActions(v.integerValue()); d->overrideActions = true; } } diff --git a/src/quick/items/qquickdroparea.cpp b/src/quick/items/qquickdroparea.cpp index 3b8f02d..f930835 100644 --- a/src/quick/items/qquickdroparea.cpp +++ b/src/quick/items/qquickdroparea.cpp @@ -421,9 +421,9 @@ void QQuickDropEvent::accept(QQmlV4Function *args) Qt::DropAction action = event->dropAction(); if (args->length() >= 1) { - v8::Handle v = (*args)[0]; - if (v->IsInt32()) - action = Qt::DropAction(v->Int32Value()); + QV4::Value v = (*args)[0]; + if (v.isInt32()) + action = Qt::DropAction(v.integerValue()); } // get action from arguments. event->setDropAction(action); -- 2.7.4