diff --git a/Sming/Core/NanoTime.h b/Sming/Core/NanoTime.h index 26cc7a46d6..ef64e7e2c4 100644 --- a/Sming/Core/NanoTime.h +++ b/Sming/Core/NanoTime.h @@ -244,12 +244,11 @@ template (); */ -template constexpr uint64_t convert() +template , UnitTickRatio>> +constexpr uint64_t convert() { - return ({ - using R = std::ratio_divide, UnitTickRatio>; - round(double(time) * R::num / R::den); - }); + return ({ round(double(time) * R::num / R::den); }); } /** diff --git a/Sming/Wiring/WString.cpp b/Sming/Wiring/WString.cpp index ae95343350..4b58bdcfd2 100644 --- a/Sming/Wiring/WString.cpp +++ b/Sming/Wiring/WString.cpp @@ -29,85 +29,85 @@ const String String::empty = ""; /* Constructors */ /*********************************************/ -String::String(const char *cstr) +String::String(const char *cstr) : String() { if (cstr) copy(cstr, strlen(cstr)); } -String::String(const FlashString& fstr) +String::String(const FlashString& fstr) : String() { setString(fstr.data(), fstr.length()); } #ifdef __GXX_EXPERIMENTAL_CXX0X__ -String::String(StringSumHelper &&rval) +String::String(StringSumHelper &&rval) : String() { move(rval); } #endif -String::String(char c) +String::String(char c) : String() { if (setLength(1)) buffer()[0] = c; } -String::String(unsigned char value, unsigned char base) +String::String(unsigned char value, unsigned char base) : String() { char buf[8 + 8 * sizeof(value)]; ultoa(value, buf, base); *this = buf; } -String::String(int value, unsigned char base) +String::String(int value, unsigned char base) : String() { char buf[8 + 8 * sizeof(value)]; itoa(value, buf, base); *this = buf; } -String::String(unsigned int value, unsigned char base) +String::String(unsigned int value, unsigned char base) : String() { char buf[8 + 8 * sizeof(value)]; ultoa(value, buf, base); *this = buf; } -String::String(long value, unsigned char base) +String::String(long value, unsigned char base) : String() { char buf[8 + 8 * sizeof(value)]; ltoa(value, buf, base); *this = buf; } -String::String(long long value, unsigned char base) +String::String(long long value, unsigned char base) : String() { char buf[8 + 8 * sizeof(value)]; lltoa(value, buf, base); *this = buf; } -String::String(unsigned long value, unsigned char base) +String::String(unsigned long value, unsigned char base) : String() { char buf[8 + 8 * sizeof(value)]; ultoa(value, buf, base); *this = buf; } -String::String(unsigned long long value, unsigned char base) +String::String(unsigned long long value, unsigned char base) : String() { char buf[8 + 8 * sizeof(value)]; ulltoa(value, buf, base); *this = buf; } -String::String(float value, unsigned char decimalPlaces) +String::String(float value, unsigned char decimalPlaces) : String() { char buf[33]; *this = dtostrf(value, 0, decimalPlaces, buf); } -String::String(double value, unsigned char decimalPlaces) +String::String(double value, unsigned char decimalPlaces) : String() { char buf[33]; *this = dtostrf(value, 0, decimalPlaces, buf); diff --git a/Sming/Wiring/WString.h b/Sming/Wiring/WString.h index da75d43885..61a82191c5 100644 --- a/Sming/Wiring/WString.h +++ b/Sming/Wiring/WString.h @@ -58,6 +58,7 @@ #include "WConstants.h" #include +#include #include #ifndef __GXX_EXPERIMENTAL_CXX0X__ @@ -123,23 +124,26 @@ class String if the initial value is null or invalid, or if memory allocation fails, the string will be marked as invalid (i.e. "if (s)" will be false). */ - String(const char *cstr = nullptr); - String(const char *cstr, size_t length) + String() : ptr{nullptr, 0, 0} + { + } + String(const char *cstr); + String(const char *cstr, size_t length) : String() { if (cstr) copy(cstr, length); } - String(const String &str) + String(const String &str) : String() { *this = str; } - explicit String(flash_string_t pstr, int length = -1) + explicit String(flash_string_t pstr, int length = -1) : String() { setString(pstr, length); } String(const FlashString& fstr); #ifdef __GXX_EXPERIMENTAL_CXX0X__ - String(String && rval) + String(String && rval) : String() { move(rval); } @@ -394,7 +398,11 @@ class String // search int indexOf(char ch, size_t fromIndex = 0) const; - int indexOf(const char* s2_buf, size_t fromIndex = 0, size_t s2_len = 0) const; + int indexOf(const char* s2_buf, size_t fromIndex, size_t s2_len) const; + int indexOf(const char* s2_buf, size_t fromIndex = 0) const + { + return indexOf(s2_buf, fromIndex, strlen(s2_buf)); + } int indexOf(const String &s2, size_t fromIndex = 0) const { return indexOf(s2.cbuffer(), fromIndex, s2.length()); @@ -438,7 +446,7 @@ class String struct PtrBuf { char* buffer; // the actual char array size_t len; // the String length (not counting the '\0') - size_t capacity : 31; // the array length minus one (for the '\0') + size_t capacity; // the array length minus one (for the '\0') }; // For small strings we can store data directly without requiring the heap struct SsoBuf { @@ -447,9 +455,6 @@ class String unsigned char set : 1; ///< true for SSO mode }; union { - struct { - size_t u32[STRING_OBJECT_SIZE / 4] = {0}; - }; PtrBuf ptr; SsoBuf sso; };