Skip to content

Commit 6ff2441

Browse files
committed
use values pointer directly
1 parent a25b275 commit 6ff2441

File tree

1 file changed

+2
-11
lines changed

1 file changed

+2
-11
lines changed

ports/esp32s2/common-hal/nvm/ByteArray.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@
2626

2727
#include "common-hal/nvm/ByteArray.h"
2828

29-
#include <string.h>
30-
3129
#include "py/runtime.h"
3230
#include "nvs_flash.h"
3331

@@ -56,17 +54,14 @@ bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self,
5654
uint32_t start_index, uint8_t* values, uint32_t len) {
5755
char index[9];
5856

59-
uint8_t buffer[len];
60-
memcpy(buffer, values, len);
61-
6257
// start nvs
6358
nvs_handle_t handle;
6459
get_nvs_handle(&handle);
6560

6661
// stage flash changes
6762
for (uint32_t i = 0; i < len; i++) {
6863
sprintf(index, "%i", start_index + i);
69-
if (nvs_set_u8(handle, (const char *)index, buffer[i]) != ESP_OK) {
64+
if (nvs_set_u8(handle, (const char *)index, values[i]) != ESP_OK) {
7065
return false;
7166
}
7267
}
@@ -84,7 +79,6 @@ bool common_hal_nvm_bytearray_set_bytes(nvm_bytearray_obj_t *self,
8479
void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self,
8580
uint32_t start_index, uint32_t len, uint8_t* values) {
8681
char index[9];
87-
uint8_t buffer[len];
8882

8983
// start nvs
9084
nvs_handle_t handle;
@@ -93,14 +87,11 @@ void common_hal_nvm_bytearray_get_bytes(nvm_bytearray_obj_t *self,
9387
// get from flash
9488
for (uint32_t i = 0; i < len; i++) {
9589
sprintf(index, "%i", start_index + i);
96-
if (nvs_get_u8(handle, (const char *)index, &buffer[i]) != ESP_OK) {
90+
if (nvs_get_u8(handle, (const char *)index, &values[i]) != ESP_OK) {
9791
mp_raise_RuntimeError(translate("NVS Error"));
9892
}
9993
}
10094

101-
// set into values
102-
memcpy(values, buffer, len);
103-
10495
// close nvs
10596
nvs_close(handle);
10697
}

0 commit comments

Comments
 (0)