Skip to content

Commit bb013d7

Browse files
committed
Stop copying and moving std::shared_ptr into std::weak_ptr
1 parent 1af12ee commit bb013d7

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

Introspection.cpp

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void Schema::AddType(response::StringType name, std::shared_ptr<object::__Type>
3232
_types.push_back({ std::move(name), std::move(type) });
3333
}
3434

35-
std::shared_ptr<object::__Type> Schema::LookupType(const response::StringType& name) const
35+
const std::shared_ptr<object::__Type>& Schema::LookupType(const response::StringType& name) const
3636
{
3737
auto itr = _typeMap.find(name);
3838

@@ -323,14 +323,9 @@ UnionType::UnionType(response::StringType name, response::StringType description
323323
{
324324
}
325325

326-
void UnionType::AddPossibleTypes(std::vector<std::shared_ptr<object::__Type>> possibleTypes)
326+
void UnionType::AddPossibleTypes(std::vector<std::weak_ptr<object::__Type>> possibleTypes)
327327
{
328-
_possibleTypes.resize(possibleTypes.size());
329-
std::transform(possibleTypes.cbegin(), possibleTypes.cend(), _possibleTypes.begin(),
330-
[](const std::shared_ptr<object::__Type>& shared)
331-
{
332-
return shared;
333-
});
328+
_possibleTypes = std::move(possibleTypes);
334329
}
335330

336331
std::future<__TypeKind> UnionType::getKind(const std::shared_ptr<service::RequestState>&) const
@@ -462,10 +457,10 @@ std::future<std::unique_ptr<std::vector<std::shared_ptr<object::__InputValue>>>>
462457
return promise.get_future();
463458
}
464459

465-
WrapperType::WrapperType(__TypeKind kind, std::shared_ptr<object::__Type> ofType)
460+
WrapperType::WrapperType(__TypeKind kind, const std::shared_ptr<object::__Type>& ofType)
466461
: BaseType(response::StringType())
467462
, _kind(kind)
468-
, _ofType(std::move(ofType))
463+
, _ofType(ofType)
469464
{
470465
}
471466

@@ -487,12 +482,12 @@ std::future<std::shared_ptr<object::__Type>> WrapperType::getOfType(const std::s
487482
return promise.get_future();
488483
}
489484

490-
Field::Field(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, std::shared_ptr<object::__Type> type)
485+
Field::Field(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, const std::shared_ptr<object::__Type>& type)
491486
: _name(std::move(name))
492487
, _description(std::move(description))
493488
, _deprecationReason(std::move(deprecationReason))
494489
, _args(std::move(args))
495-
, _type(std::move(type))
490+
, _type(type)
496491
{
497492
}
498493

@@ -556,10 +551,10 @@ std::future<std::unique_ptr<response::StringType>> Field::getDeprecationReason(c
556551
return promise.get_future();
557552
}
558553

559-
InputValue::InputValue(response::StringType name, response::StringType description, std::shared_ptr<object::__Type> type, response::StringType defaultValue)
554+
InputValue::InputValue(response::StringType name, response::StringType description, const std::shared_ptr<object::__Type>& type, response::StringType defaultValue)
560555
: _name(std::move(name))
561556
, _description(std::move(description))
562-
, _type(std::move(type))
557+
, _type(type)
563558
, _defaultValue(std::move(defaultValue))
564559
{
565560
}

include/graphqlservice/Introspection.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class Schema : public object::__Schema
3131
void AddMutationType(std::shared_ptr<ObjectType> mutation);
3232
void AddSubscriptionType(std::shared_ptr<ObjectType> subscription);
3333
void AddType(response::StringType name, std::shared_ptr<object::__Type> type);
34-
std::shared_ptr<object::__Type> LookupType(const response::StringType& name) const;
34+
const std::shared_ptr<object::__Type>& LookupType(const response::StringType& name) const;
3535
void AddDirective(std::shared_ptr<object::__Directive> directive);
3636

3737
// Accessors
@@ -127,7 +127,7 @@ class UnionType : public BaseType
127127
public:
128128
explicit UnionType(response::StringType name, response::StringType description);
129129

130-
void AddPossibleTypes(std::vector<std::shared_ptr<object::__Type>> possibleTypes);
130+
void AddPossibleTypes(std::vector<std::weak_ptr<object::__Type>> possibleTypes);
131131

132132
// Accessors
133133
std::future<__TypeKind> getKind(const std::shared_ptr<service::RequestState>& state) const override;
@@ -186,7 +186,7 @@ class InputObjectType : public BaseType
186186
class WrapperType : public BaseType
187187
{
188188
public:
189-
explicit WrapperType(__TypeKind kind, std::shared_ptr<object::__Type> ofType);
189+
explicit WrapperType(__TypeKind kind, const std::shared_ptr<object::__Type>& ofType);
190190

191191
// Accessors
192192
std::future<__TypeKind> getKind(const std::shared_ptr<service::RequestState>& state) const override;
@@ -200,7 +200,7 @@ class WrapperType : public BaseType
200200
class Field : public object::__Field
201201
{
202202
public:
203-
explicit Field(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, std::shared_ptr<object::__Type> type);
203+
explicit Field(response::StringType name, response::StringType description, std::unique_ptr<response::StringType>&& deprecationReason, std::vector<std::shared_ptr<InputValue>> args, const std::shared_ptr<object::__Type>& type);
204204

205205
// Accessors
206206
std::future<response::StringType> getName(const std::shared_ptr<service::RequestState>& state) const override;
@@ -221,7 +221,7 @@ class Field : public object::__Field
221221
class InputValue : public object::__InputValue
222222
{
223223
public:
224-
explicit InputValue(response::StringType name, response::StringType description, std::shared_ptr<object::__Type> type, response::StringType defaultValue);
224+
explicit InputValue(response::StringType name, response::StringType description, const std::shared_ptr<object::__Type>& type, response::StringType defaultValue);
225225

226226
// Accessors
227227
std::future<response::StringType> getName(const std::shared_ptr<service::RequestState>& state) const override;

0 commit comments

Comments
 (0)