... ...

[C++] Compiler remove for-loop in putString methods (original) (raw)

Hello devs!

I have a message:

... ...

The sbe-tool generate c++ code:

MarketDataResponse &putText(std::string_view str)
{
    const size_t srcLength = str.length();
    if (srcLength > 64)
    {
         throw std::runtime_error("string too large for putText [E106]");
    }

    size_t length = srcLength < 64 ? srcLength : 64;
    std::memcpy(m_buffer + m_offset + 54, str.data(), length);
    for (size_t start = srcLength; start < length; ++start)
    {
        m_buffer[m_offset + 54 + start] = 0;
    }

    return *this;
}

The problem is compiler (gcc 7 in my case) removes for-loop in case of flag -O2 set.

Is it possible to fix the issue inside sbe-tool?

Thanks