@@ -12,24 +12,26 @@ namespace nix::fetchers {
1212
1313using InputSchemeMap = std::map<std::string_view, std::shared_ptr<InputScheme>>;
1414
15- std::unique_ptr<InputSchemeMap> inputSchemes = nullptr ;
15+ static InputSchemeMap & inputSchemes ()
16+ {
17+ static InputSchemeMap inputSchemeMap;
18+ return inputSchemeMap;
19+ }
1620
1721void registerInputScheme (std::shared_ptr<InputScheme> && inputScheme)
1822{
19- if (!inputSchemes)
20- inputSchemes = std::make_unique<InputSchemeMap>();
2123 auto schemeName = inputScheme->schemeName ();
22- if (inputSchemes-> count (schemeName) > 0 )
24+ if (! inputSchemes (). emplace (schemeName, std::move (inputScheme)). second )
2325 throw Error (" Input scheme with name %s already registered" , schemeName);
24- inputSchemes->insert_or_assign (schemeName, std::move (inputScheme));
2526}
2627
27- nlohmann::json dumpRegisterInputSchemeInfo () {
28+ nlohmann::json dumpRegisterInputSchemeInfo ()
29+ {
2830 using nlohmann::json;
2931
3032 auto res = json::object ();
3133
32- for (auto & [name, scheme] : * inputSchemes) {
34+ for (auto & [name, scheme] : inputSchemes () ) {
3335 auto & r = res[name] = json::object ();
3436 r[" allowedAttrs" ] = scheme->allowedAttrs ();
3537 }
@@ -57,7 +59,7 @@ Input Input::fromURL(
5759 const Settings & settings,
5860 const ParsedURL & url, bool requireTree)
5961{
60- for (auto & [_, inputScheme] : * inputSchemes) {
62+ for (auto & [_, inputScheme] : inputSchemes () ) {
6163 auto res = inputScheme->inputFromURL (settings, url, requireTree);
6264 if (res) {
6365 experimentalFeatureSettings.require (inputScheme->experimentalFeature ());
@@ -91,8 +93,8 @@ Input Input::fromAttrs(const Settings & settings, Attrs && attrs)
9193 };
9294
9395 std::shared_ptr<InputScheme> inputScheme = ({
94- auto i = inputSchemes-> find ( schemeName);
95- i == inputSchemes-> end () ? nullptr : i-> second ;
96+ auto i = get ( inputSchemes (), schemeName);
97+ i ? *i : nullptr ;
9698 });
9799
98100 if (!inputScheme) return raw ();
0 commit comments