1
0
Fork 0

Added a toAqlValue in ManagedDocumentResult that should be called from outside. This figures out if we have to copy the content into the AqlValue or if we could just point to the raw data.

This commit is contained in:
Michael Hackstein 2017-04-05 15:32:45 +02:00
parent 039c6fbd16
commit e64cadde7d
3 changed files with 27 additions and 6 deletions

View File

@ -512,10 +512,8 @@ AqlItemBlock* IndexBlock::getSome(size_t atLeast, size_t atMost) {
}
}
if (_cursor->collection()->readDocument(_trx, token, *_mmdr)) {
uint8_t const* vpack = _mmdr->vpack(); //back();
// TODO use internal toAQL function
res->setValue(_returned, static_cast<arangodb::aql::RegisterId>(curRegs),
AqlValue(VPackSlice(vpack)));
_mmdr->createAqlValue());
if (_returned > 0) {
// re-use already copied AqlValues
@ -531,10 +529,8 @@ AqlItemBlock* IndexBlock::getSome(size_t atLeast, size_t atMost) {
callback = [&](DocumentIdentifierToken const& token) {
TRI_ASSERT(res.get() != nullptr);
if (_cursor->collection()->readDocument(_trx, token, *_mmdr)) {
uint8_t const* vpack = _mmdr->vpack(); //back();
// TODO use internal toAQL function
res->setValue(_returned, static_cast<arangodb::aql::RegisterId>(curRegs),
AqlValue(VPackSlice(vpack)));
_mmdr->createAqlValue());
if (_returned > 0) {
// re-use already copied AqlValues

View File

@ -22,12 +22,14 @@
////////////////////////////////////////////////////////////////////////////////
#include "ManagedDocumentResult.h"
#include "Aql/AqlValue.h"
#include <velocypack/Builder.h>
#include <velocypack/Slice.h>
#include <velocypack/velocypack-aliases.h>
using namespace arangodb;
using namespace arangodb::aql;
void ManagedDocumentResult::clone(ManagedDocumentResult& cloned) const {
cloned.reset();
@ -100,3 +102,17 @@ void ManagedDocumentResult::addToBuilder(velocypack::Builder& builder, bool allo
builder.add(velocypack::Slice(_vpack));
}
}
// @brief Creates an AQLValue with the content of this ManagedDocumentResult
// The caller is responsible to properly destroy() the
// returned value
AqlValue ManagedDocumentResult::createAqlValue() const {
TRI_ASSERT(!empty());
if (canUseInExternal()) {
// No need to copy. Underlying structure guarantees that Slices stay
// valid
return AqlValue(_vpack, AqlValueFromManagedDocument());
}
// Do copy. Otherwise the slice may go out of scope
return AqlValue(VPackSlice(_vpack));
}

View File

@ -32,6 +32,10 @@ namespace velocypack {
class Builder;
}
namespace aql {
struct AqlValue;
}
class ManagedDocumentResult {
public:
ManagedDocumentResult() :
@ -91,6 +95,11 @@ class ManagedDocumentResult {
void addToBuilder(velocypack::Builder& builder, bool allowExternals) const;
// @brief Creates an AQLValue with the content of this ManagedDocumentResult
// The caller is responsible to properly destroy() the
// returned value
aql::AqlValue createAqlValue() const;
private:
uint64_t _length;
TRI_voc_rid_t _lastRevisionId;