Skip to content

Commit 8e38105

Browse files
committed
refactor(BLE): don't pass primitive types by reference
There is no need to pass primitive types by reference, especially by non-const reference as it was in BLECharacteristic. Pass primitive types by value instead, as it should be, and used everywhere else except this one odd class. This allows allows to pass function result as `setValue()` argument without creating temporary variable.
1 parent 15be2a5 commit 8e38105

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

libraries/BLE/src/BLECharacteristic.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -375,14 +375,14 @@ void BLECharacteristic::setValue(String value) {
375375
setValue((uint8_t *)(value.c_str()), value.length());
376376
} // setValue
377377

378-
void BLECharacteristic::setValue(uint16_t &data16) {
378+
void BLECharacteristic::setValue(uint16_t data16) {
379379
uint8_t temp[2];
380380
temp[0] = data16;
381381
temp[1] = data16 >> 8;
382382
setValue(temp, 2);
383383
} // setValue
384384

385-
void BLECharacteristic::setValue(uint32_t &data32) {
385+
void BLECharacteristic::setValue(uint32_t data32) {
386386
uint8_t temp[4];
387387
temp[0] = data32;
388388
temp[1] = data32 >> 8;
@@ -391,7 +391,7 @@ void BLECharacteristic::setValue(uint32_t &data32) {
391391
setValue(temp, 4);
392392
} // setValue
393393

394-
void BLECharacteristic::setValue(int &data32) {
394+
void BLECharacteristic::setValue(int data32) {
395395
uint8_t temp[4];
396396
temp[0] = data32;
397397
temp[1] = data32 >> 8;
@@ -400,12 +400,12 @@ void BLECharacteristic::setValue(int &data32) {
400400
setValue(temp, 4);
401401
} // setValue
402402

403-
void BLECharacteristic::setValue(float &data32) {
403+
void BLECharacteristic::setValue(float data32) {
404404
float temp = data32;
405405
setValue((uint8_t *)&temp, 4);
406406
} // setValue
407407

408-
void BLECharacteristic::setValue(double &data64) {
408+
void BLECharacteristic::setValue(double data64) {
409409
double temp = data64;
410410
setValue((uint8_t *)&temp, 8);
411411
} // setValue

libraries/BLE/src/BLECharacteristic.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,11 @@ class BLECharacteristic {
186186
void setCallbacks(BLECharacteristicCallbacks *pCallbacks);
187187
void setValue(uint8_t *data, size_t size);
188188
void setValue(String value);
189-
void setValue(uint16_t &data16);
190-
void setValue(uint32_t &data32);
191-
void setValue(int &data32);
192-
void setValue(float &data32);
193-
void setValue(double &data64);
189+
void setValue(uint16_t data16);
190+
void setValue(uint32_t data32);
191+
void setValue(int data32);
192+
void setValue(float data32);
193+
void setValue(double data64);
194194
String toString();
195195
uint16_t getHandle();
196196
void setAccessPermissions(uint8_t perm);

0 commit comments

Comments
 (0)