1
0
Fork 0

micro optimizations

This commit is contained in:
jsteemann 2016-05-16 21:32:01 +02:00
parent c64b146d29
commit 578f3bb919
8 changed files with 27 additions and 23 deletions

View File

@ -165,7 +165,7 @@ AqlValue AqlValue::at(int64_t position, bool& mustDestroy,
}
if (position >= 0 && position < n) {
if (doCopy) {
mustDestroy = true;
mustDestroy = (type() == VPACK_MANAGED);
return AqlValue(s.at(position));
}
// return a reference to an existing slice
@ -237,7 +237,7 @@ AqlValue AqlValue::getKeyAttribute(arangodb::AqlTransaction* trx,
VPackSlice found = Transaction::extractKeyFromDocument(s);
if (!found.isNone()) {
if (doCopy) {
mustDestroy = true;
mustDestroy = (type() == VPACK_MANAGED);
return AqlValue(found);
}
// return a reference to an existing slice
@ -278,7 +278,7 @@ AqlValue AqlValue::getIdAttribute(arangodb::AqlTransaction* trx,
}
if (!found.isNone()) {
if (doCopy) {
mustDestroy = true;
mustDestroy = (type() == VPACK_MANAGED);
return AqlValue(found);
}
// return a reference to an existing slice
@ -314,7 +314,7 @@ AqlValue AqlValue::getFromAttribute(arangodb::AqlTransaction* trx,
VPackSlice found = Transaction::extractFromFromDocument(s);
if (!found.isNone()) {
if (doCopy) {
mustDestroy = true;
mustDestroy = (type() == VPACK_MANAGED);
return AqlValue(found);
}
// return a reference to an existing slice
@ -350,7 +350,7 @@ AqlValue AqlValue::getToAttribute(arangodb::AqlTransaction* trx,
VPackSlice found = Transaction::extractToFromDocument(s);
if (!found.isNone()) {
if (doCopy) {
mustDestroy = true;
mustDestroy = (type() == VPACK_MANAGED);
return AqlValue(found);
}
// return a reference to an existing slice
@ -392,7 +392,7 @@ AqlValue AqlValue::get(arangodb::AqlTransaction* trx,
}
if (!found.isNone()) {
if (doCopy) {
mustDestroy = true;
mustDestroy = (type() == VPACK_MANAGED);
return AqlValue(found);
}
// return a reference to an existing slice
@ -434,7 +434,7 @@ AqlValue AqlValue::get(arangodb::AqlTransaction* trx,
}
if (!found.isNone()) {
if (doCopy) {
mustDestroy = true;
mustDestroy = (type() == VPACK_MANAGED);
return AqlValue(found);
}
// return a reference to an existing slice

View File

@ -32,12 +32,13 @@ using namespace arangodb::aql;
/// @brief create the accessor
AttributeAccessor::AttributeAccessor(
std::vector<std::string> const& attributeParts, Variable const* variable)
std::vector<std::string>&& attributeParts, Variable const* variable)
: _attributeParts(attributeParts),
_variable(variable),
_type(EXTRACT_MULTI) {
TRI_ASSERT(_variable != nullptr);
TRI_ASSERT(!_attributeParts.empty());
// determine accessor type
if (_attributeParts.size() == 1) {

View File

@ -38,7 +38,7 @@ struct Variable;
/// @brief AttributeAccessor
class AttributeAccessor {
public:
AttributeAccessor(std::vector<std::string> const&, Variable const*);
AttributeAccessor(std::vector<std::string>&&, Variable const*);
~AttributeAccessor() = default;
/// @brief execute the accessor

View File

@ -173,6 +173,8 @@ bool FilterBlock::getBlock(size_t atLeast, size_t atMost) {
_buffer.pop_front(); // Block was useless, just try again
delete cur; // free this block
throwIfKilled(); // check if we were aborted
}
return true;

View File

@ -34,7 +34,6 @@
#include "Aql/SortNode.h"
#include "Aql/TraversalNode.h"
#include "Aql/WalkerWorker.h"
#include "Basics/StringBuffer.h"
using namespace arangodb::basics;
using namespace arangodb::aql;

View File

@ -346,7 +346,7 @@ void Expression::analyzeExpression() {
auto v = static_cast<Variable const*>(member->getData());
// specialize the simple expression into an attribute accessor
_accessor = new AttributeAccessor(parts, v);
_accessor = new AttributeAccessor(std::move(parts), v);
_type = ATTRIBUTE;
_built = true;
}
@ -769,7 +769,6 @@ AqlValue Expression::executeSimpleExpressionFCall(
auto member = node->getMemberUnchecked(0);
TRI_ASSERT(member->type == NODE_TYPE_ARRAY);
VPackBuilder builder;
size_t const n = member->numMembers();
VPackFunctionParameters parameters;
@ -782,9 +781,7 @@ AqlValue Expression::executeSimpleExpressionFCall(
auto arg = member->getMemberUnchecked(i);
if (arg->type == NODE_TYPE_COLLECTION) {
builder.clear();
builder.add(VPackValue(arg->getString()));
parameters.emplace_back(AqlValue(builder));
parameters.emplace_back(AqlValue(arg->getString()));
destroyParameters.push_back(true);
} else {
bool localMustDestroy;
@ -1356,8 +1353,8 @@ AqlValue Expression::executeSimpleExpressionArithmetic(
return AqlValue(VelocyPackHelper::ZeroValue());
}
VPackBuilder builder;
TransactionBuilderLeaser builder(trx);
mustDestroy = true; // builder = dynamic data
builder.add(VPackValue(result));
return AqlValue(builder);
builder->add(VPackValue(result));
return AqlValue(*builder.get());
}

View File

@ -533,8 +533,14 @@ AqlItemBlock* IndexBlock::getSome(size_t atLeast, size_t atMost) {
// we do not need to do a lookup in
// getPlanNode()->_registerPlan->varInfo,
// but can just take cur->getNrRegs() as registerId:
res->setValue(j, static_cast<arangodb::aql::RegisterId>(curRegs),
AqlValue(_documents[_posInDocs++]));
auto doc = _documents[_posInDocs++];
if (doc.isExternal()) {
res->setValue(j, static_cast<arangodb::aql::RegisterId>(curRegs),
AqlValue(doc.resolveExternal().begin()));
} else {
res->setValue(j, static_cast<arangodb::aql::RegisterId>(curRegs),
AqlValue(doc));
}
// No harm done, if the setValue throws!
}
}

View File

@ -231,8 +231,7 @@ void arangodb::aql::removeRedundantSortsRule(Optimizer* opt,
}
std::unordered_set<ExecutionNode*> toUnlink;
arangodb::basics::StringBuffer buffer(TRI_UNKNOWN_MEM_ZONE);
arangodb::basics::StringBuffer buffer(TRI_UNKNOWN_MEM_ZONE, false);
for (auto const& n : nodes) {
if (toUnlink.find(n) != toUnlink.end()) {
@ -1367,7 +1366,7 @@ void arangodb::aql::removeRedundantCalculationsRule(
return;
}
arangodb::basics::StringBuffer buffer(TRI_UNKNOWN_MEM_ZONE);
arangodb::basics::StringBuffer buffer(TRI_UNKNOWN_MEM_ZONE, false);
std::unordered_map<VariableId, Variable const*> replacements;
for (auto const& n : nodes) {