Reduced memory allocations when generating raw buffer from EDBG AVR command frames

This commit is contained in:
Nav
2022-02-28 00:54:19 +00:00
parent 3163f5c1e3
commit 081fba5cbd

View File

@@ -81,7 +81,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
* @return * @return
*/ */
[[nodiscard]] auto getRawCommandFrame() const { [[nodiscard]] auto getRawCommandFrame() const {
auto rawCommand = std::vector<unsigned char>(5); auto rawCommand = std::vector<unsigned char>(5 + this->payload.size());
rawCommand[0] = 0x0E; // Start of frame rawCommand[0] = 0x0E; // Start of frame
rawCommand[1] = 0x00; // Protocol version rawCommand[1] = 0x00; // Protocol version
@@ -92,11 +92,7 @@ namespace Bloom::DebugToolDrivers::Protocols::CmsisDap::Edbg::Avr
rawCommand[4] = static_cast<unsigned char>(this->protocolHandlerId); rawCommand[4] = static_cast<unsigned char>(this->protocolHandlerId);
if (!this->payload.empty()) { if (!this->payload.empty()) {
rawCommand.insert( std::copy(this->payload.begin(), this->payload.end(), rawCommand.begin() + 5);
rawCommand.end(),
this->payload.begin(),
this->payload.end()
);
} }
return rawCommand; return rawCommand;