From 3fd954fc6a24b6581e5bc54792aec3354254faee Mon Sep 17 00:00:00 2001 From: jsteemann Date: Tue, 15 Mar 2016 10:40:37 +0100 Subject: [PATCH] micro optimizations --- arangod/Aql/Functions.cpp | 37 +++++---------------- arangod/RestHandler/RestDocumentHandler.cpp | 7 ++-- 2 files changed, 12 insertions(+), 32 deletions(-) diff --git a/arangod/Aql/Functions.cpp b/arangod/Aql/Functions.cpp index 1e4b2e54ff..135a31008c 100644 --- a/arangod/Aql/Functions.cpp +++ b/arangod/Aql/Functions.cpp @@ -56,7 +56,6 @@ using namespace arangodb; using namespace arangodb::aql; -using CollectionNameResolver = arangodb::CollectionNameResolver; using VertexId = arangodb::traverser::VertexId; //////////////////////////////////////////////////////////////////////////////// @@ -284,26 +283,6 @@ static double ValueToNumber(VPackSlice const& slice, bool& isValid) { return 0.0; } -//////////////////////////////////////////////////////////////////////////////// -/// @brief converts a value into a boolean value -//////////////////////////////////////////////////////////////////////////////// - -static bool ValueToBoolean(VPackSlice const& slice) { - if (slice.isBoolean()) { - return slice.getBoolean(); - } - if (slice.isNumber()) { - return slice.getNumericValue() != 0.0; - } - if (slice.isString()) { - return slice.getStringLength() != 0; - } - if (slice.isArray() || slice.isObject()) { - return true; - } - return false; -} - //////////////////////////////////////////////////////////////////////////////// /// @brief extract a boolean parameter from an array //////////////////////////////////////////////////////////////////////////////// @@ -3165,8 +3144,8 @@ AqlValue Functions::Push(arangodb::aql::Query* query, b->add(it); } if (n == 3) { - VPackSlice unique = ExtractFunctionParameter(trx, parameters, 2); - if (!ValueToBoolean(unique) || !ListContainsElement(list, toPush)) { + AqlValue unique = ExtractFunctionParameterValue(trx, parameters, 2); + if (!unique.toBoolean() || !ListContainsElement(list, toPush)) { b->add(toPush); } } else { @@ -3244,8 +3223,8 @@ AqlValue Functions::Append(arangodb::aql::Query* query, bool unique = false; if (n == 3) { - VPackSlice uniqueSlice = ExtractFunctionParameter(trx, parameters, 2); - unique = ValueToBoolean(uniqueSlice); + AqlValue a = ExtractFunctionParameterValue(trx, parameters, 2); + unique = a.toBoolean(); } std::shared_ptr b = query->getSharedBuilder(); @@ -3297,8 +3276,8 @@ AqlValue Functions::Unshift(arangodb::aql::Query* query, VPackSlice toAppend = ExtractFunctionParameter(trx, parameters, 1); bool unique = false; if (n == 3) { - VPackSlice uniqueSlice = ExtractFunctionParameter(trx, parameters, 2); - unique = ValueToBoolean(uniqueSlice); + AqlValue a = ExtractFunctionParameterValue(trx, parameters, 2); + unique = a.toBoolean(); } if (unique && list.isArray() && ListContainsElement(list, toAppend)) { @@ -4027,8 +4006,8 @@ AqlValue Functions::Position(arangodb::aql::Query* query, bool returnIndex = false; if (n == 3) { - VPackSlice returnIndexSlice = ExtractFunctionParameter(trx, parameters, 2); - returnIndex = ValueToBoolean(returnIndexSlice); + AqlValue a = ExtractFunctionParameterValue(trx, parameters, 2); + returnIndex = a.toBoolean(); } std::shared_ptr b = query->getSharedBuilder(); diff --git a/arangod/RestHandler/RestDocumentHandler.cpp b/arangod/RestHandler/RestDocumentHandler.cpp index 72862e9531..86b340d7bb 100644 --- a/arangod/RestHandler/RestDocumentHandler.cpp +++ b/arangod/RestHandler/RestDocumentHandler.cpp @@ -114,6 +114,10 @@ bool RestDocumentHandler::createDocument() { if (!parseSuccess) { return false; } + + arangodb::OperationOptions opOptions; + opOptions.waitForSync = extractBooleanParameter("waitForSync", false); + opOptions.returnNew = extractBooleanParameter("returnNew", false); // find and load collection given by name or identifier auto transactionContext(StandaloneTransactionContext::Create(_vocbase)); @@ -131,9 +135,6 @@ bool RestDocumentHandler::createDocument() { return false; } - arangodb::OperationOptions opOptions; - opOptions.waitForSync = extractBooleanParameter("waitForSync", false); - opOptions.returnNew = extractBooleanParameter("returnNew", false); arangodb::OperationResult result = trx.insert(collectionName, body, opOptions); // Will commit if no error occured.