CpuUid: to save memory, overloaded type cast std::string operator uses minimal implementation instead of snprintf

pull/5557/head
Michael Kaplan 2017-11-24 09:49:16 +01:00
parent eb9910c509
commit 3406ff262f
2 changed files with 6 additions and 4 deletions

View File

@ -14,7 +14,6 @@
* limitations under the License.
*/
#include <cstdio>
#include "hal/cpu_uid_api.h"
#include "drivers/CpuUid.h"
@ -22,6 +21,8 @@
namespace mbed {
const char CpuUid::_hexChars[16] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
CpuUid::CpuUid() : _data(NULL)
{
_size = cpu_uid_get_length();
@ -43,12 +44,11 @@ CpuUid::~CpuUid()
CpuUid::operator std::string()
{
std::string str;
char buf[3];
for (int i = 0; i < _size; ++i)
{
snprintf(buf, 3, "%.2X", _data[i]);
str += buf;
str += _hexChars[_data[i] >> 4];
str += _hexChars[_data[i] & 0x0F];
}
return str;

View File

@ -87,6 +87,8 @@ public:
private:
uint8_t * _data;
int _size;
static const char _hexChars[16];
};
} // namespace mbed