Repository: bitcoin/bitcoin
File: src/script/descriptor.cpp (C++)

Code before:
        for (const auto& arg : m_subdescriptor_args) {
            if (!arg->IsSolvable()) return false;
        }
        return true;
    }

    // NOLINTNEXTLINE(misc-no-recursion)
    bool IsRange() const final
    {
        for (const auto& pubkey : m_pubkey_args) {
            if (pubkey->IsRange()) return true;
        }
        for (const auto& arg : m_subdescriptor_args) {
            if (arg->IsRange()) return true;
        }
        return false;
    }

    // NOLINTNEXTLINE(misc-no-recursion)
    virtual bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, const StringType type, const DescriptorCache* cache = nullptr) const
    {
        size_t pos = 0;
        for (const auto& scriptarg : m_subdescriptor_args) {
            if (pos++) ret += ",";
            std::string tmp;
            if (!scriptarg->ToStringHelper(arg, tmp, type, cache)) return false;
            ret += tmp;
        }
        return true;
    }

    // NOLINTNEXTLINE(misc-no-recursion)
    virtual bool ToStringHelper(const SigningProvider* arg, std::string& out, const StringType type, const DescriptorCache* cache = nullptr) const
    {
        std::string extra = ToStringExtra();
        size_t pos = extra.size() > 0 ? 1 : 0;
        std::string ret = m_name + "(" + extra;
        for (const auto& pubkey : m_pubkey_args) {
            if (pos++) ret += ",";
            std::string tmp;
            switch (type) {
                case StringType::NORMALIZED:
                    if (!pubkey->ToNormalizedString(*arg, tmp, cache)) return false;
                    break;
                case StringType::PRIVATE:
                    if (!pubkey->ToPrivateString(*arg, tmp)) return false;
                    break;
                case StringType::PUBLIC:
                    tmp = pubkey->ToString();
                    break;
                case StringType::COMPAT:

Review comment (suggestion):
nit: Could reuse one temporary provider to reduce alloc churn.

```suggestion
       FlatSigningProvider tmp_provider;
        for (const auto& pubkey : m_pubkey_args) {
            tmp_provider.keys.clear();
            pubkey->GetPrivKey(0, arg, tmp_provider);
            if (tmp_provider.keys.empty()) return false;
        }
```

Code after:
    };

    // NOLINTNEXTLINE(misc-no-recursion)
    bool IsSolvable() const override
    {
        for (const auto& arg : m_subdescriptor_args) {
            if (!arg->IsSolvable()) return false;
        }
        return true;
    }

    // NOLINTNEXTLINE(misc-no-recursion)
    bool HavePrivateKeys(const SigningProvider& arg) const override
    {
        if (m_pubkey_args.empty() && m_subdescriptor_args.empty()) return false;

        for (const auto& sub: m_subdescriptor_args) {
            if (!sub->HavePrivateKeys(arg)) return false;
        }

        FlatSigningProvider tmp_provider;
        for (const auto& pubkey : m_pubkey_args) {
            tmp_provider.keys.clear();
            pubkey->GetPrivKey(0, arg, tmp_provider);
            if (tmp_provider.keys.empty()) return false;
        }

        return true;
    }

    // NOLINTNEXTLINE(misc-no-recursion)
    bool IsRange() const final
    {
        for (const auto& pubkey : m_pubkey_args) {
            if (pubkey->IsRange()) return true;
        }
        for (const auto& arg : m_subdescriptor_args) {
            if (arg->IsRange()) return true;
        }
        return false;
    }

    // NOLINTNEXTLINE(misc-no-recursion)
    virtual bool ToStringSubScriptHelper(const SigningProvider* arg, std::string& ret, const StringType type, const DescriptorCache* cache = nullptr) const
    {
        size_t pos = 0;
        bool is_private{type == StringType::PRIVATE};
        // For private string output, track if at least one key has a private key available.
        // Initialize to true for non-private types.
        bool any_success{!is_private};
        for (const auto& scriptarg : m_subdescriptor_args) {