Skip to content

Commit c6cf0a0

Browse files
committed
Copy shared_ptr which can shift
1 parent 0f79f28 commit c6cf0a0

File tree

2 files changed

+19
-19
lines changed

2 files changed

+19
-19
lines changed

include/graphqlservice/GraphQLSchema.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ class Schema : public std::enable_shared_from_this<Schema>
4545
GRAPHQLSERVICE_EXPORT void AddType(std::string_view name, std::shared_ptr<BaseType> type);
4646
GRAPHQLSERVICE_EXPORT const std::shared_ptr<const BaseType>& LookupType(
4747
std::string_view name) const;
48-
GRAPHQLSERVICE_EXPORT const std::shared_ptr<const BaseType>& WrapType(
49-
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType);
48+
GRAPHQLSERVICE_EXPORT std::shared_ptr<const BaseType> WrapType(
49+
introspection::TypeKind kind, std::shared_ptr<const BaseType> ofType);
5050
GRAPHQLSERVICE_EXPORT void AddDirective(std::shared_ptr<Directive> directive);
5151

5252
// Accessors
@@ -282,7 +282,7 @@ class WrapperType : public BaseType
282282
explicit WrapperType(init&& params);
283283

284284
GRAPHQLSERVICE_EXPORT static std::shared_ptr<WrapperType> Make(
285-
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType);
285+
introspection::TypeKind kind, std::weak_ptr<const BaseType> ofType);
286286

287287
// Accessors
288288
GRAPHQLSERVICE_EXPORT const std::weak_ptr<const BaseType>& ofType() const noexcept final;
@@ -303,7 +303,7 @@ class Field : public std::enable_shared_from_this<Field>
303303

304304
GRAPHQLSERVICE_EXPORT static std::shared_ptr<Field> Make(std::string_view name,
305305
std::string_view description, std::optional<std::string_view> deprecationReason,
306-
const std::shared_ptr<const BaseType>& type,
306+
std::weak_ptr<const BaseType> type,
307307
std::initializer_list<std::shared_ptr<InputValue>> args = {});
308308

309309
// Accessors
@@ -333,7 +333,7 @@ class InputValue : public std::enable_shared_from_this<InputValue>
333333
explicit InputValue(init&& params);
334334

335335
GRAPHQLSERVICE_EXPORT static std::shared_ptr<InputValue> Make(std::string_view name,
336-
std::string_view description, const std::shared_ptr<const BaseType>& type,
336+
std::string_view description, std::weak_ptr<const BaseType> type,
337337
std::string_view defaultValue);
338338

339339
// Accessors

src/GraphQLSchema.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ const std::shared_ptr<const BaseType>& Schema::LookupType(std::string_view name)
6060
return _types[itr->second].second;
6161
}
6262

63-
const std::shared_ptr<const BaseType>& Schema::WrapType(
64-
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType)
63+
std::shared_ptr<const BaseType> Schema::WrapType(
64+
introspection::TypeKind kind, std::shared_ptr<const BaseType> ofType)
6565
{
6666
auto& wrappers = (kind == introspection::TypeKind::LIST) ? _listWrappers : _nonNullWrappers;
6767
auto itr = wrappers.find(ofType);
@@ -387,18 +387,18 @@ const std::vector<std::shared_ptr<const InputValue>>& InputObjectType::inputFiel
387387
struct WrapperType::init
388388
{
389389
introspection::TypeKind kind;
390-
const std::shared_ptr<const BaseType>& ofType;
390+
std::weak_ptr<const BaseType> ofType;
391391
};
392392

393393
std::shared_ptr<WrapperType> WrapperType::Make(
394-
introspection::TypeKind kind, const std::shared_ptr<const BaseType>& ofType)
394+
introspection::TypeKind kind, std::weak_ptr<const BaseType> ofType)
395395
{
396-
return std::make_shared<WrapperType>(init { kind, ofType });
396+
return std::make_shared<WrapperType>(init { kind, std::move(ofType) });
397397
}
398398

399399
WrapperType::WrapperType(init&& params)
400400
: BaseType(params.kind, std::string_view())
401-
, _ofType(params.ofType)
401+
, _ofType(std::move(params.ofType))
402402
{
403403
}
404404

@@ -412,15 +412,15 @@ struct Field::init
412412
std::string_view name;
413413
std::string_view description;
414414
std::optional<std::string_view> deprecationReason;
415-
const std::shared_ptr<const BaseType>& type;
415+
std::weak_ptr<const BaseType> type;
416416
std::vector<std::shared_ptr<const InputValue>> args;
417417
};
418418

419419
std::shared_ptr<Field> Field::Make(std::string_view name, std::string_view description,
420-
std::optional<std::string_view> deprecationReason, const std::shared_ptr<const BaseType>& type,
420+
std::optional<std::string_view> deprecationReason, std::weak_ptr<const BaseType> type,
421421
std::initializer_list<std::shared_ptr<InputValue>> args)
422422
{
423-
init params { name, description, deprecationReason, type };
423+
init params { name, description, deprecationReason, std::move(type) };
424424

425425
params.args.resize(args.size());
426426
std::copy(args.begin(), args.end(), params.args.begin());
@@ -432,7 +432,7 @@ Field::Field(init&& params)
432432
: _name(params.name)
433433
, _description(params.description)
434434
, _deprecationReason(params.deprecationReason)
435-
, _type(params.type)
435+
, _type(std::move(params.type))
436436
, _args(std::move(params.args))
437437
{
438438
}
@@ -466,20 +466,20 @@ struct InputValue::init
466466
{
467467
std::string_view name;
468468
std::string_view description;
469-
const std::shared_ptr<const BaseType>& type;
469+
std::weak_ptr<const BaseType> type;
470470
std::string_view defaultValue;
471471
};
472472

473473
std::shared_ptr<InputValue> InputValue::Make(std::string_view name, std::string_view description,
474-
const std::shared_ptr<const BaseType>& type, std::string_view defaultValue)
474+
std::weak_ptr<const BaseType> type, std::string_view defaultValue)
475475
{
476-
return std::make_shared<InputValue>(init { name, description, type, defaultValue });
476+
return std::make_shared<InputValue>(init { name, description, std::move(type), defaultValue });
477477
}
478478

479479
InputValue::InputValue(init&& params)
480480
: _name(params.name)
481481
, _description(params.description)
482-
, _type(params.type)
482+
, _type(std::move(params.type))
483483
, _defaultValue(params.defaultValue)
484484
{
485485
}

0 commit comments

Comments
 (0)