From acaa28e916b0d89e3c243cc3f8a46fcf74d8be63 Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Tue, 22 Aug 2017 18:24:56 +0200 Subject: Optimize array access Avoid the expensive modulo operation when indexing into an array, and do a simple conditional subtraction instead. Change-Id: I57a78c0cf94b010e4bc226b9b2a5c2e3251498f8 Reviewed-by: Erik Verbruggen --- src/qml/jsruntime/qv4arraydata_p.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/qml/jsruntime/qv4arraydata_p.h b/src/qml/jsruntime/qv4arraydata_p.h index e1de2e82e6..5028778877 100644 --- a/src/qml/jsruntime/qv4arraydata_p.h +++ b/src/qml/jsruntime/qv4arraydata_p.h @@ -144,7 +144,7 @@ DECLARE_HEAP_OBJECT(ArrayData, Base) { V4_ASSERT_IS_TRIVIAL(ArrayData) struct SimpleArrayData : public ArrayData { - uint mappedIndex(uint index) const { return (index + offset) % values.alloc; } + uint mappedIndex(uint index) const { index += offset; if (index > values.alloc) index -= values.alloc; return index; } const Value &data(uint index) const { return values[mappedIndex(index)]; } void setData(EngineBase *e, uint index, Value newVal) { values.set(e, mappedIndex(index), newVal); -- cgit v1.2.3