Skip to content

Commit

Permalink
Merge pull request #40 from wravery/master
Browse files Browse the repository at this point in the history
Fix #39, plus a lingering short-string-optimization bug
  • Loading branch information
wravery committed Feb 7, 2019
2 parents 25f98da + 4b653f4 commit 7e3acf9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
5 changes: 1 addition & 4 deletions GraphQLService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1082,10 +1082,7 @@ std::future<response::Value> Object::resolve(const SelectionSetParams & selectio

response::Value result(response::Type::Map);

if (data.size() > 0)
{
result.emplace_back(strData, std::move(data));
}
result.emplace_back(strData, std::move(data));

if (errors.size() > 0)
{
Expand Down
10 changes: 9 additions & 1 deletion GraphQLTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,15 @@ ast<const char*>::~ast()
ast<std::string> parseString(std::string&& input)
{
ast<std::string> result { std::move(input), nullptr };
memory_input<> in(result.input.c_str(), result.input.size(), "GraphQL");
const size_t length = result.input.size();

if (length < sizeof(result.input))
{
// Overflow the short string optimization so it uses a heap allocation.
result.input.resize(sizeof(result.input));
}

memory_input<> in(result.input.c_str(), length, "GraphQL");

result.root = parse_tree::parse<document, ast_node, ast_selector, nothing, ast_control>(std::move(in));

Expand Down
5 changes: 1 addition & 4 deletions include/graphqlservice/GraphQLService.h
Original file line number Diff line number Diff line change
Expand Up @@ -541,10 +541,7 @@ struct ModifiedResult

response::Value document(response::Type::Map);

if (data.size() > 0)
{
document.emplace_back(strData, std::move(data));
}
document.emplace_back(strData, std::move(data));

if (errors.size() > 0)
{
Expand Down

0 comments on commit 7e3acf9

Please sign in to comment.