Skip to content

Commit 7e3acf9

Browse files
authored
Merge pull request #40 from wravery/master
Fix #39, plus a lingering short-string-optimization bug
2 parents 25f98da + 4b653f4 commit 7e3acf9

File tree

3 files changed

+11
-9
lines changed

3 files changed

+11
-9
lines changed

GraphQLService.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1082,10 +1082,7 @@ std::future<response::Value> Object::resolve(const SelectionSetParams & selectio
10821082

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

1085-
if (data.size() > 0)
1086-
{
1087-
result.emplace_back(strData, std::move(data));
1088-
}
1085+
result.emplace_back(strData, std::move(data));
10891086

10901087
if (errors.size() > 0)
10911088
{

GraphQLTree.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,15 @@ ast<const char*>::~ast()
659659
ast<std::string> parseString(std::string&& input)
660660
{
661661
ast<std::string> result { std::move(input), nullptr };
662-
memory_input<> in(result.input.c_str(), result.input.size(), "GraphQL");
662+
const size_t length = result.input.size();
663+
664+
if (length < sizeof(result.input))
665+
{
666+
// Overflow the short string optimization so it uses a heap allocation.
667+
result.input.resize(sizeof(result.input));
668+
}
669+
670+
memory_input<> in(result.input.c_str(), length, "GraphQL");
663671

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

include/graphqlservice/GraphQLService.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -541,10 +541,7 @@ struct ModifiedResult
541541

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

544-
if (data.size() > 0)
545-
{
546-
document.emplace_back(strData, std::move(data));
547-
}
544+
document.emplace_back(strData, std::move(data));
548545

549546
if (errors.size() > 0)
550547
{

0 commit comments

Comments
 (0)