Skip to content

Commit d735105

Browse files
committed
Return by const reference where applicable
1 parent 65ed7b7 commit d735105

File tree

8 files changed

+22
-34
lines changed

8 files changed

+22
-34
lines changed

samples/star_wars/DroidData.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@ Droid::Droid(response::StringType&& id, std::optional<response::StringType>&& na
1717
{
1818
}
1919

20-
const response::StringType& Droid::id() const noexcept
21-
{
22-
return id_;
23-
}
24-
2520
void Droid::addFriends(
2621
std::vector<std::variant<std::shared_ptr<Human>, std::shared_ptr<Droid>>> friends) noexcept
2722
{
@@ -41,12 +36,12 @@ void Droid::addFriends(
4136
});
4237
}
4338

44-
response::StringType Droid::getId() const noexcept
39+
const response::StringType& Droid::getId() const noexcept
4540
{
4641
return id_;
4742
}
4843

49-
std::optional<response::StringType> Droid::getName() const noexcept
44+
const std::optional<response::StringType>& Droid::getName() const noexcept
5045
{
5146
return name_;
5247
}
@@ -100,7 +95,7 @@ std::optional<std::vector<std::optional<Episode>>> Droid::getAppearsIn() const n
10095
return result.empty() ? std::nullopt : std::make_optional(std::move(result));
10196
}
10297

103-
std::optional<response::StringType> Droid::getPrimaryFunction() const noexcept
98+
const std::optional<response::StringType>& Droid::getPrimaryFunction() const noexcept
10499
{
105100
return primaryFunction_;
106101
}

samples/star_wars/DroidData.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ class Droid
2121
std::vector<Episode>&& appearsIn,
2222
std::optional<response::StringType>&& primaryFunction) noexcept;
2323

24-
const response::StringType& id() const noexcept;
2524
void addFriends(std::vector<SharedHero> friends) noexcept;
2625

27-
response::StringType getId() const noexcept;
28-
std::optional<response::StringType> getName() const noexcept;
26+
const response::StringType& getId() const noexcept;
27+
const std::optional<response::StringType>& getName() const noexcept;
2928
std::optional<std::vector<std::shared_ptr<service::Object>>> getFriends() const noexcept;
3029
std::optional<std::vector<std::optional<Episode>>> getAppearsIn() const noexcept;
31-
std::optional<response::StringType> getPrimaryFunction() const noexcept;
30+
const std::optional<response::StringType>& getPrimaryFunction() const noexcept;
3231

3332
private:
3433
const response::StringType id_;

samples/star_wars/HumanData.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ Human::Human(response::StringType&& id, std::optional<response::StringType>&& na
1616
{
1717
}
1818

19-
const response::StringType& Human::id() const noexcept
20-
{
21-
return id_;
22-
}
23-
2419
void Human::addFriends(std::vector<SharedHero> friends) noexcept
2520
{
2621
friends_.resize(friends.size());
@@ -39,12 +34,12 @@ void Human::addFriends(std::vector<SharedHero> friends) noexcept
3934
});
4035
}
4136

42-
response::StringType Human::getId() const noexcept
37+
const response::StringType& Human::getId() const noexcept
4338
{
4439
return id_;
4540
}
4641

47-
std::optional<response::StringType> Human::getName() const noexcept
42+
const std::optional<response::StringType>& Human::getName() const noexcept
4843
{
4944
return name_;
5045
}
@@ -98,7 +93,7 @@ std::optional<std::vector<std::optional<Episode>>> Human::getAppearsIn() const n
9893
return result.empty() ? std::nullopt : std::make_optional(std::move(result));
9994
}
10095

101-
std::optional<response::StringType> Human::getHomePlanet() const noexcept
96+
const std::optional<response::StringType>& Human::getHomePlanet() const noexcept
10297
{
10398
return homePlanet_;
10499
}

samples/star_wars/HumanData.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ class Human
1919
std::vector<Episode>&& appearsIn,
2020
std::optional<response::StringType>&& homePlanet) noexcept;
2121

22-
const response::StringType& id() const noexcept;
2322
void addFriends(std::vector<SharedHero> friends) noexcept;
2423

25-
response::StringType getId() const noexcept;
26-
std::optional<response::StringType> getName() const noexcept;
24+
const response::StringType& getId() const noexcept;
25+
const std::optional<response::StringType>& getName() const noexcept;
2726
std::optional<std::vector<std::shared_ptr<service::Object>>> getFriends() const noexcept;
2827
std::optional<std::vector<std::optional<Episode>>> getAppearsIn() const noexcept;
29-
std::optional<response::StringType> getHomePlanet() const noexcept;
28+
const std::optional<response::StringType>& getHomePlanet() const noexcept;
3029

3130
private:
3231
const response::StringType id_;

samples/star_wars/ReviewData.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ response::IntType Review::getStars() const noexcept
1616
return stars_;
1717
}
1818

19-
std::optional<response::StringType> Review::getCommentary() const noexcept
19+
const std::optional<response::StringType>& Review::getCommentary() const noexcept
2020
{
2121
return commentary_;
2222
}

samples/star_wars/ReviewData.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Review
1717
response::IntType stars, std::optional<response::StringType>&& commentary) noexcept;
1818

1919
response::IntType getStars() const noexcept;
20-
std::optional<response::StringType> getCommentary() const noexcept;
20+
const std::optional<response::StringType>& getCommentary() const noexcept;
2121

2222
private:
2323
const response::IntType stars_;

samples/star_wars/StarWarsData.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -100,16 +100,16 @@ std::shared_ptr<service::Request> GetService() noexcept
100100
};
101101

102102
std::map<response::StringType, std::shared_ptr<learn::Human>> humans {
103-
{ luke->id(), luke },
104-
{ vader->id(), vader },
105-
{ han->id(), han },
106-
{ leia->id(), leia },
107-
{ tarkin->id(), tarkin },
103+
{ luke->getId(), luke },
104+
{ vader->getId(), vader },
105+
{ han->getId(), han },
106+
{ leia->getId(), leia },
107+
{ tarkin->getId(), tarkin },
108108
};
109109

110110
std::map<response::StringType, std::shared_ptr<learn::Droid>> droids {
111-
{ threepio->id(), threepio },
112-
{ artoo->id(), artoo },
111+
{ threepio->getId(), threepio },
112+
{ artoo->getId(), artoo },
113113
};
114114

115115
auto query =

samples/today/TodayMock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ class CompleteTaskPayload
417417
return std::make_shared<object::Task>(_task);
418418
}
419419

420-
std::optional<response::StringType> getClientMutationId() const noexcept
420+
const std::optional<response::StringType>& getClientMutationId() const noexcept
421421
{
422422
return _clientMutationId;
423423
}

0 commit comments

Comments
 (0)