From 54de7050bd37dcc9912d3a63f811da1b7ccdcc1f Mon Sep 17 00:00:00 2001 From: cathery Date: Fri, 17 Apr 2020 12:04:36 +0300 Subject: [PATCH] Use memcpy --- source/ControllerSwitch/SwitchUSBEndpoint.cpp | 10 ++-------- source/ControllerSwitch/SwitchUSBInterface.cpp | 16 +++------------- 2 files changed, 5 insertions(+), 21 deletions(-) diff --git a/source/ControllerSwitch/SwitchUSBEndpoint.cpp b/source/ControllerSwitch/SwitchUSBEndpoint.cpp index 05fa1e3..e61faeb 100644 --- a/source/ControllerSwitch/SwitchUSBEndpoint.cpp +++ b/source/ControllerSwitch/SwitchUSBEndpoint.cpp @@ -44,10 +44,7 @@ Result SwitchUSBEndpoint::Write(const void *inBuffer, size_t bufferSize) return -1; u32 transferredSize = 0; - for (size_t byte = 0; byte != bufferSize; ++byte) - { - static_cast(m_buffer)[byte] = static_cast(inBuffer)[byte]; - } + memcpy(m_buffer, inBuffer, bufferSize); Result rc = usbHsEpPostBuffer(&m_epSession, m_buffer, bufferSize, &transferredSize); @@ -69,10 +66,7 @@ Result SwitchUSBEndpoint::Read(void *outBuffer, size_t bufferSize) if (R_SUCCEEDED(rc)) { - for (u32 byte = 0; byte != transferredSize; ++byte) - { - static_cast(outBuffer)[byte] = static_cast(m_buffer)[byte]; - } + memcpy(outBuffer, m_buffer, transferredSize); } return rc; } diff --git a/source/ControllerSwitch/SwitchUSBInterface.cpp b/source/ControllerSwitch/SwitchUSBInterface.cpp index abf295f..f83d8d7 100644 --- a/source/ControllerSwitch/SwitchUSBInterface.cpp +++ b/source/ControllerSwitch/SwitchUSBInterface.cpp @@ -72,20 +72,13 @@ Result SwitchUSBInterface::ControlTransfer(u8 bmRequestType, u8 bmRequest, u16 w u32 transferredSize; - for (u16 byte = 0; byte != wLength; ++byte) - { - static_cast(temp_buffer)[byte] = static_cast(buffer)[byte]; - } + memcpy(temp_buffer, buffer, wLength); Result rc = usbHsIfCtrlXfer(&m_session, bmRequestType, bmRequest, wValue, wIndex, wLength, temp_buffer, &transferredSize); if (R_SUCCEEDED(rc)) { - memset(buffer, 0, wLength); - for (u32 byte = 0; byte != transferredSize; ++byte) - { - static_cast(buffer)[byte] = static_cast(temp_buffer)[byte]; - } + memcpy(buffer, temp_buffer, transferredSize); } free(temp_buffer); return rc; @@ -99,10 +92,7 @@ Result SwitchUSBInterface::ControlTransfer(u8 bmRequestType, u8 bmRequest, u16 w u32 transferredSize; - for (u16 byte = 0; byte != wLength; ++byte) - { - static_cast(temp_buffer)[byte] = static_cast(buffer)[byte]; - } + memcpy(temp_buffer, buffer, wLength); Result rc = usbHsIfCtrlXfer(&m_session, bmRequestType, bmRequest, wValue, wIndex, wLength, temp_buffer, &transferredSize); free(temp_buffer);