Use memory from EvaluationContext in awesome functions

Reviewers: mferencevic, msantl, mtomic

Reviewed By: msantl

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D2133
This commit is contained in:
Teon Banek 2019-06-07 16:21:16 +02:00
parent 3fd14e2d5f
commit 65ab2574bc
3 changed files with 260 additions and 226 deletions

File diff suppressed because it is too large Load Diff

View File

@ -381,22 +381,23 @@ class ExpressionEvaluator : public ExpressionVisitor<TypedValue> {
for (size_t i = 0; i < function.arguments_.size(); ++i) {
arguments[i] = function.arguments_[i]->Accept(*this);
}
// TODO: Update awesome_memgraph_functions to use the allocator from ctx_
return TypedValue(function.function_(
arguments, function.arguments_.size(), *ctx_, dba_),
ctx_->memory);
auto res = function.function_(arguments, function.arguments_.size(),
*ctx_, dba_);
CHECK(res.GetMemoryResource() == ctx_->memory);
return res;
} else {
TypedValue::TVector arguments(ctx_->memory);
arguments.reserve(function.arguments_.size());
for (const auto &argument : function.arguments_) {
arguments.emplace_back(argument->Accept(*this));
}
// TODO: Update awesome_memgraph_functions to use the allocator from ctx_
return TypedValue(
function.function_(arguments.data(), arguments.size(), *ctx_, dba_),
ctx_->memory);
auto res =
function.function_(arguments.data(), arguments.size(), *ctx_, dba_);
CHECK(res.GetMemoryResource() == ctx_->memory);
return res;
}
}
TypedValue Visit(Reduce &reduce) override {
auto list_value = reduce.list_->Accept(*this);
if (list_value.IsNull()) {

View File

@ -175,7 +175,7 @@ template <class TAllocator>
std::basic_string<char, std::char_traits<char>, TAllocator> *Replace(
std::basic_string<char, std::char_traits<char>, TAllocator> *out,
const std::string_view &src, const std::string_view &match,
const std::string_view &replacement, const TAllocator &alloc) {
const std::string_view &replacement) {
// TODO: This could be implemented much more efficiently.
*out = src;
for (size_t pos = out->find(match); pos != std::string::npos;
@ -190,7 +190,7 @@ inline std::string Replace(const std::string_view &src,
const std::string_view &match,
const std::string_view &replacement) {
std::string res;
Replace(&res, src, match, replacement, std::allocator<char>());
Replace(&res, src, match, replacement);
return res;
}