Skip to content

Type#GetLoadDependencies(): VERIFY() that no nullptr is returned#10155

Merged
yhabteab merged 2 commits intomasterfrom
Type-GetLoadDependencies-nullptr
Sep 20, 2024
Merged

Type#GetLoadDependencies(): VERIFY() that no nullptr is returned#10155
yhabteab merged 2 commits intomasterfrom
Type-GetLoadDependencies-nullptr

Conversation

@Al2Klimov
Copy link
Member

@Al2Klimov Al2Klimov commented Sep 16, 2024

@Al2Klimov Al2Klimov added the core/quality Improve code, libraries, algorithms, inline docs label Sep 16, 2024
@Al2Klimov Al2Klimov requested a review from yhabteab September 16, 2024 10:24
@cla-bot cla-bot bot added the cla/signed label Sep 16, 2024
@Al2Klimov Al2Klimov force-pushed the Type-GetLoadDependencies-nullptr branch from 66bb803 to 6a11cf1 Compare September 18, 2024 08:56
If a specific type shall return no deps, the base method already does that.
@Al2Klimov Al2Klimov force-pushed the Type-GetLoadDependencies-nullptr branch 2 times, most recently from 3a77ff8 to d298508 Compare September 19, 2024 14:39
@Al2Klimov Al2Klimov force-pushed the Type-GetLoadDependencies-nullptr branch from d298508 to c24713a Compare September 19, 2024 14:43
@Al2Klimov Al2Klimov requested a review from yhabteab September 19, 2024 14:55
Comment on lines +386 to +387
for (auto& dep : klass.LoadDependencies)
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's much better, but why are you using two different loops for declaring and verifying them? Can't you just combine them like that?

Suggested change
for (auto& dep : klass.LoadDependencies)
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
for (auto& dep : klass.LoadDependencies) {
m_Impl << "\t\tauto type" << dep << " (GetByName(\"" << dep << "\").get());" << std::endl;
m_Impl << "\t\tVERIFY(type" << dep << ");" << std::endl;
}
m_Impl << std::endl << "\t\treturn std::unordered_set<Type*>{";

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I prefer this:

const std::unordered_set<Type*>& TypeImpl<Service>::GetLoadDependencies() const
{
	static const auto deps ([] {
		auto typeApiListener (GetByName("ApiListener").get());
		auto typeEndpoint (GetByName("Endpoint").get());
		auto typeHost (GetByName("Host").get());
		auto typeZone (GetByName("Zone").get());

		VERIFY(typeApiListener);
		VERIFY(typeEndpoint);
		VERIFY(typeHost);
		VERIFY(typeZone);

		return std::unordered_set{ typeApiListener, typeEndpoint, typeHost, typeZone, };
	}());

	return deps;
}

@Al2Klimov Al2Klimov requested a review from yhabteab September 19, 2024 15:16
Copy link
Member

@yhabteab yhabteab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, let's do this!

@yhabteab yhabteab added this to the 2.15.0 milestone Sep 20, 2024
@yhabteab yhabteab merged commit dac747f into master Sep 20, 2024
@yhabteab yhabteab deleted the Type-GetLoadDependencies-nullptr branch September 20, 2024 10:29
@Al2Klimov Al2Klimov removed their assignment May 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla/signed core/quality Improve code, libraries, algorithms, inline docs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants