From cc00bb8897391d15120dc30614f46d1aa14ec1f2 Mon Sep 17 00:00:00 2001 From: Jan Steemann Date: Thu, 4 Dec 2014 16:33:48 +0100 Subject: [PATCH] optimizations --- arangod/Aql/AqlItemBlock.h | 9 +++++++++ arangod/Aql/AqlValue.cpp | 20 ++++++++++++-------- lib/Basics/JsonHelper.h | 8 ++++++++ 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/arangod/Aql/AqlItemBlock.h b/arangod/Aql/AqlItemBlock.h index 79b34c5eb4..e01964998e 100644 --- a/arangod/Aql/AqlItemBlock.h +++ b/arangod/Aql/AqlItemBlock.h @@ -103,6 +103,15 @@ namespace triagens { TRI_ASSERT(_data.capacity() > index * _nrRegs + varNr); return _data[index * _nrRegs + varNr]; } + +//////////////////////////////////////////////////////////////////////////////// +/// @brief getValue, get the value of a register by reference +//////////////////////////////////////////////////////////////////////////////// + + AqlValue const& getValueReference (size_t index, RegisterId varNr) const { + TRI_ASSERT(_data.capacity() > index * _nrRegs + varNr); + return _data[index * _nrRegs + varNr]; + } //////////////////////////////////////////////////////////////////////////////// /// @brief setValue, set the current value of a register diff --git a/arangod/Aql/AqlValue.cpp b/arangod/Aql/AqlValue.cpp index bf8d1cf512..feadd2378c 100644 --- a/arangod/Aql/AqlValue.cpp +++ b/arangod/Aql/AqlValue.cpp @@ -756,17 +756,21 @@ AqlValue AqlValue::CreateFromBlocks (triagens::arango::AqlTransaction* trx, for (auto it = src.begin(); it != src.end(); ++it) { auto current = (*it); RegisterId const n = current->getNrRegs(); + + std::vector> registers; + for (RegisterId j = 0; j < n; ++j) { + // temporaries don't have a name and won't be included + if (variableNames[j][0] != '\0') { + registers.emplace_back(std::make_pair(j, current->getDocumentCollection(j))); + } + } for (size_t i = 0; i < current->size(); ++i) { - Json values(Json::Array); + Json values(Json::Array, registers.size()); - for (RegisterId j = 0; j < n; ++j) { - if (variableNames[j][0] != '\0') { - // temporaries don't have a name and won't be included - // Variables from depth 0 are excluded, too, unless the - // COLLECT statement is on level 0 as well. - values.set(variableNames[j].c_str(), current->getValue(i, j).toJson(trx, current->getDocumentCollection(j))); - } + // only enumerate the registers that are left + for (auto const& reg : registers) { + values.set(variableNames[reg.first], current->getValueReference(i, reg.first).toJson(trx, reg.second)); } json->add(values); diff --git a/lib/Basics/JsonHelper.h b/lib/Basics/JsonHelper.h index eadfcc4d03..aebc246367 100644 --- a/lib/Basics/JsonHelper.h +++ b/lib/Basics/JsonHelper.h @@ -702,6 +702,14 @@ namespace triagens { TRI_Insert3ArrayJson(_zone, _json, name, sub.steal()); return *this; } + + Json& set (std::string const& name, Json sub) { + if (! TRI_IsArrayJson(_json)) { + throw JsonException("Json is no array"); + } + TRI_Insert3ArrayJson(_zone, _json, name.c_str(), sub.steal()); + return *this; + } //////////////////////////////////////////////////////////////////////////////// /// @brief this is a syntactic shortcut for the set method using operator()