Skip to content

Commit 50ef472

Browse files
Define all of XBeeAddress64 in XBee.h
Since this is a utility class that should really be a very thin wrapper around the actual data, the compiler should be able to inline all operations, instead of having to do a full function call just to load or store a few bytes. This removes the explicit super-constructor calls and rewrites the constructors to use initializer lists instead of assigning values in the body (which is more consise, and allows for constexpr next) This saves up to a 30 bytes of program spaces on the supplied examples, probably more for more complex programs.
1 parent c94a815 commit 50ef472

File tree

2 files changed

+14
-58
lines changed

2 files changed

+14
-58
lines changed

XBee.cpp

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,53 +1014,6 @@ void PayloadRequest::setPayloadLength(uint8_t payloadLength) {
10141014
_payloadLength = payloadLength;
10151015
}
10161016

1017-
1018-
XBeeAddress::XBeeAddress() {
1019-
1020-
}
1021-
1022-
XBeeAddress64::XBeeAddress64() : XBeeAddress() {
1023-
1024-
}
1025-
1026-
XBeeAddress64::XBeeAddress64(uint32_t msb, uint32_t lsb) : XBeeAddress() {
1027-
_msb = msb;
1028-
_lsb = lsb;
1029-
}
1030-
1031-
XBeeAddress64::XBeeAddress64(uint64_t addr) : XBeeAddress() {
1032-
set(addr);
1033-
}
1034-
1035-
uint32_t XBeeAddress64::getMsb() {
1036-
return _msb;
1037-
}
1038-
1039-
void XBeeAddress64::setMsb(uint32_t msb) {
1040-
_msb = msb;
1041-
}
1042-
1043-
uint32_t XBeeAddress64::getLsb() {
1044-
return _lsb;
1045-
}
1046-
1047-
void XBeeAddress64::setLsb(uint32_t lsb) {
1048-
_lsb = lsb;
1049-
}
1050-
1051-
uint64_t XBeeAddress64::get() {
1052-
return (static_cast<uint64_t>(_msb) << 32) | _lsb;
1053-
}
1054-
1055-
void XBeeAddress64::set(uint64_t addr) {
1056-
_msb = addr >> 32;
1057-
_lsb = addr;
1058-
}
1059-
1060-
XBeeAddress64::operator uint64_t() {
1061-
return get();
1062-
}
1063-
10641017
#ifdef SERIES_2
10651018

10661019
ZBTxRequest::ZBTxRequest() : PayloadRequest(ZB_TX_REQUEST, DEFAULT_FRAME_ID, NULL, 0) {

XBee.h

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ class XBeeResponse {
287287

288288
class XBeeAddress {
289289
public:
290-
XBeeAddress();
290+
XBeeAddress() {};
291291
};
292292

293293
/**
@@ -299,16 +299,19 @@ class XBeeAddress {
299299
*/
300300
class XBeeAddress64 : public XBeeAddress {
301301
public:
302-
XBeeAddress64(uint64_t addr);
303-
XBeeAddress64(uint32_t msb, uint32_t lsb);
304-
XBeeAddress64();
305-
uint32_t getMsb();
306-
uint32_t getLsb();
307-
uint64_t get();
308-
operator uint64_t();
309-
void setMsb(uint32_t msb);
310-
void setLsb(uint32_t lsb);
311-
void set(uint64_t addr);
302+
XBeeAddress64(uint64_t addr) : _msb(addr >> 32), _lsb(addr) {}
303+
XBeeAddress64(uint32_t msb, uint32_t lsb) : _msb(msb), _lsb(lsb) {}
304+
XBeeAddress64() {}
305+
uint32_t getMsb() {return _msb;}
306+
uint32_t getLsb() {return _lsb;}
307+
uint64_t get() {return (static_cast<uint64_t>(_msb) << 32) | _lsb;}
308+
operator uint64_t() {return get();}
309+
void setMsb(uint32_t msb) {_msb = msb;}
310+
void setLsb(uint32_t lsb) {_lsb = lsb;}
311+
void set(uint64_t addr) {
312+
_msb = addr >> 32;
313+
_lsb = addr;
314+
}
312315
private:
313316
// Once https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66511 is
314317
// fixed, it might make sense to merge these into a uint64_t.

0 commit comments

Comments
 (0)