Various beast cleanups

This commit is contained in:
Vinnie Falco
2013-07-03 08:55:06 -07:00
parent 3c993884cd
commit 03948cd685
5 changed files with 23 additions and 24 deletions

View File

@@ -148,15 +148,14 @@ public:
volatile Type value; volatile Type value;
private: private:
#if BEAST_CLANG || __GNUC__ >= 4 template <typename Dest, typename Source>
#define BEAST_ATTRIBUTE_MAY_ALIAS __attribute__((__may_alias__)) static inline Dest castTo (Source value) noexcept { union { Dest d; Source s; } u; u.s = value; return u.d; }
#else
#define BEAST_ATTRIBUTE_MAY_ALIAS static inline Type castFrom32Bit (int32 value) noexcept { return castTo <Type, int32> (value); }
#endif static inline Type castFrom64Bit (int64 value) noexcept { return castTo <Type, int64> (value); }
static inline Type castFrom32Bit (int32 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; } static inline int32 castTo32Bit (Type value) noexcept { return castTo <int32, Type> (value); }
static inline Type castFrom64Bit (int64 value) noexcept { Type * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (Type*)&value; return *tmp; } static inline int64 castTo64Bit (Type value) noexcept { return castTo <int64, Type> (value); }
static inline int32 castTo32Bit (Type value) noexcept { int32 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int32*)&value; return *tmp; }
static inline int64 castTo64Bit (Type value) noexcept { int64 * BEAST_ATTRIBUTE_MAY_ALIAS tmp = (int64*)&value; return *tmp; }
Type operator++ (int); // better to just use pre-increment with atomics.. Type operator++ (int); // better to just use pre-increment with atomics..
Type operator-- (int); Type operator-- (int);

View File

@@ -54,7 +54,8 @@ void Process::terminate()
BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger() BEAST_API bool BEAST_CALLTYPE beast_isRunningUnderDebugger()
{ {
bassertfalse; // XXX not implemented for FreeBSD! // XXX not implemented for FreeBSD!
bassertfalse;
return false; return false;
} }

View File

@@ -78,7 +78,7 @@ int SystemStats::getMemorySizeInMegabytes()
struct sysinfo sysi; struct sysinfo sysi;
if (sysinfo (&sysi) == 0) if (sysinfo (&sysi) == 0)
return (sysi.totalram * sysi.mem_unit / (1024 * 1024)); return sysi.totalram * sysi.mem_unit / (1024 * 1024);
return 0; return 0;
} }
@@ -94,11 +94,8 @@ String SystemStats::getLogonName()
const char* user = getenv ("USER"); const char* user = getenv ("USER");
if (user == nullptr) if (user == nullptr)
{ if (passwd* const pw = getpwuid (getuid()))
struct passwd* const pw = getpwuid (getuid());
if (pw != nullptr)
user = pw->pw_name; user = pw->pw_name;
}
return CharPointer_UTF8 (user); return CharPointer_UTF8 (user);
} }
@@ -117,11 +114,12 @@ String SystemStats::getComputerName()
return String::empty; return String::empty;
} }
String getLocaleValue (nl_item key) static String getLocaleValue (nl_item key)
{ {
const char* oldLocale = ::setlocale (LC_ALL, ""); const char* oldLocale = ::setlocale (LC_ALL, "");
return String (const_cast <const char*> (nl_langinfo (key))); String result (String::fromUTF8 (nl_langinfo (key)));
::setlocale (LC_ALL, oldLocale); ::setlocale (LC_ALL, oldLocale);
return result;
} }
String SystemStats::getUserLanguage() { return getLocaleValue (_NL_IDENTIFICATION_LANGUAGE); } String SystemStats::getUserLanguage() { return getLocaleValue (_NL_IDENTIFICATION_LANGUAGE); }
@@ -141,7 +139,7 @@ SystemStats::CPUFlags::CPUFlags()
} }
//============================================================================== //==============================================================================
uint32 beast_millisecondsSinceStartup() noexcept uint32 BEAST_millisecondsSinceStartup() noexcept
{ {
timespec t; timespec t;
clock_gettime (CLOCK_MONOTONIC, &t); clock_gettime (CLOCK_MONOTONIC, &t);

View File

@@ -1200,8 +1200,8 @@ public:
dest = result.getCharPointer(); dest = result.getCharPointer();
} }
StringCreationHelper (const String::CharPointerType& source_) StringCreationHelper (const String::CharPointerType s)
: source (source_), dest (nullptr), allocatedBytes (StringHolder::getAllocatedNumBytes (source)), bytesWritten (0) : source (s), dest (nullptr), allocatedBytes (StringHolder::getAllocatedNumBytes (s)), bytesWritten (0)
{ {
result.preallocateBytes (allocatedBytes); result.preallocateBytes (allocatedBytes);
dest = result.getCharPointer(); dest = result.getCharPointer();
@@ -1531,7 +1531,8 @@ String String::quoted (const beast_wchar quoteCharacter) const
} }
//============================================================================== //==============================================================================
static String::CharPointerType findTrimmedEnd (const String::CharPointerType& start, String::CharPointerType end) static String::CharPointerType findTrimmedEnd (const String::CharPointerType start,
String::CharPointerType end)
{ {
while (end > start) while (end > start)
{ {

View File

@@ -30,14 +30,14 @@ struct TextDiffHelpers
StringRegion (const String& s) noexcept StringRegion (const String& s) noexcept
: text (s.getCharPointer()), start (0), length (s.length()) {} : text (s.getCharPointer()), start (0), length (s.length()) {}
StringRegion (const String::CharPointerType& t, int s, int len) noexcept StringRegion (const String::CharPointerType t, int s, int len) noexcept
: text (t), start (s), length (len) {} : text (t), start (s), length (len) {}
String::CharPointerType text; String::CharPointerType text;
int start, length; int start, length;
}; };
static void addInsertion (TextDiff& td, const String::CharPointerType& text, int index, int length) static void addInsertion (TextDiff& td, const String::CharPointerType text, int index, int length)
{ {
TextDiff::Change c; TextDiff::Change c;
c.insertedText = String (text, (size_t) length); c.insertedText = String (text, (size_t) length);
@@ -99,7 +99,7 @@ struct TextDiffHelpers
} }
static int findLongestCommonSubstring (String::CharPointerType a, const int lenA, static int findLongestCommonSubstring (String::CharPointerType a, const int lenA,
const String::CharPointerType& b, const int lenB, const String::CharPointerType b, const int lenB,
int& indexInA, int& indexInB) int& indexInA, int& indexInB)
{ {
if (lenA == 0 || lenB == 0) if (lenA == 0 || lenB == 0)