mirror of
https://github.com/XRPLF/rippled.git
synced 2025-11-23 20:45:51 +00:00
Reduce Beast public interface and eliminate unused code:
Beast includes a lot of code for encapsulating cross-platform differences which are not used or needed by rippled. Additionally, a lot of that code implements functionality that is available from the standard library. This moves away from custom implementations of features that the standard library provides and reduces the number of platform-specific interfaces andfeatures that Beast makes available. Highlights include: * Use std:: instead of beast implementations when possible * Reduce the use of beast::String in public interfaces * Remove Windows-specific COM and Registry code * Reduce the public interface of beast::File * Reduce the public interface of beast::SystemStats * Remove unused sysctl/getsysinfo functions * Remove beast::Logger
This commit is contained in:
committed by
Vinnie Falco
parent
fefdb32d08
commit
186ca9c235
@@ -30,12 +30,13 @@
|
||||
|
||||
#include <beast/ByteOrder.h>
|
||||
#include <beast/Memory.h>
|
||||
#include <beast/StaticAssert.h>
|
||||
#include <beast/Arithmetic.h>
|
||||
#include <beast/HeapBlock.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace beast {
|
||||
|
||||
#if BEAST_MSVC
|
||||
@@ -54,6 +55,21 @@ static inline CharPointer_wchar_t castToCharPointer_wchar_t (const void* t) noex
|
||||
return CharPointer_wchar_t (static_cast <const CharPointer_wchar_t::CharType*> (t));
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
// Let me know if any of these assertions fail on your system!
|
||||
#if BEAST_NATIVE_WCHAR_IS_UTF8
|
||||
static_assert (sizeof (wchar_t) == 1,
|
||||
"The size of a wchar_t should be exactly 1 byte for UTF-8");
|
||||
#elif BEAST_NATIVE_WCHAR_IS_UTF16
|
||||
static_assert (sizeof (wchar_t) == 2,
|
||||
"The size of a wchar_t should be exactly 2 bytes for UTF-16");
|
||||
#elif BEAST_NATIVE_WCHAR_IS_UTF32
|
||||
static_assert (sizeof (wchar_t) == 4,
|
||||
"The size of a wchar_t should be exactly 4 bytes for UTF-32");
|
||||
#else
|
||||
#error "The size of a wchar_t is not known!"
|
||||
#endif
|
||||
|
||||
//==============================================================================
|
||||
class StringHolder
|
||||
{
|
||||
@@ -199,7 +215,7 @@ public:
|
||||
if (b->refCount.get() <= 0 && b->allocatedNumBytes >= numBytes)
|
||||
return text;
|
||||
|
||||
CharPointerType newText (createUninitialisedBytes (bmax (b->allocatedNumBytes, numBytes)));
|
||||
CharPointerType newText (createUninitialisedBytes (std::max (b->allocatedNumBytes, numBytes)));
|
||||
memcpy (newText.getAddress(), text.getAddress(), b->allocatedNumBytes);
|
||||
release (b);
|
||||
|
||||
@@ -225,20 +241,6 @@ private:
|
||||
return reinterpret_cast <StringHolder*> (reinterpret_cast <char*> (text.getAddress())
|
||||
- (reinterpret_cast <size_t> (reinterpret_cast <StringHolder*> (1)->text) - 1));
|
||||
}
|
||||
|
||||
void compileTimeChecks()
|
||||
{
|
||||
// Let me know if any of these assertions fail on your system!
|
||||
#if BEAST_NATIVE_WCHAR_IS_UTF8
|
||||
static_bassert (sizeof (wchar_t) == 1);
|
||||
#elif BEAST_NATIVE_WCHAR_IS_UTF16
|
||||
static_bassert (sizeof (wchar_t) == 2);
|
||||
#elif BEAST_NATIVE_WCHAR_IS_UTF32
|
||||
static_bassert (sizeof (wchar_t) == 4);
|
||||
#else
|
||||
#error "native wchar_t size is unknown"
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
StringHolder StringHolder::empty;
|
||||
@@ -1126,7 +1128,7 @@ public:
|
||||
|
||||
if (bytesWritten > allocatedBytes)
|
||||
{
|
||||
allocatedBytes += bmax ((size_t) 8, allocatedBytes / 16);
|
||||
allocatedBytes += std::max ((size_t) 8, allocatedBytes / 16);
|
||||
const size_t destOffset = (size_t) (((char*) dest.getAddress()) - (char*) result.getCharPointer().getAddress());
|
||||
result.preallocateBytes (allocatedBytes);
|
||||
dest = addBytesToPointer (result.getCharPointer().getAddress(), (int) destOffset);
|
||||
@@ -1349,12 +1351,12 @@ String String::substring (int start) const
|
||||
|
||||
String String::dropLastCharacters (const int numberToDrop) const
|
||||
{
|
||||
return String (text, (size_t) bmax (0, length() - numberToDrop));
|
||||
return String (text, (size_t) std::max (0, length() - numberToDrop));
|
||||
}
|
||||
|
||||
String String::getLastCharacters (const int numCharacters) const
|
||||
{
|
||||
return String (text + bmax (0, length() - bmax (0, numCharacters)));
|
||||
return String (text + std::max (0, length() - std::max (0, numCharacters)));
|
||||
}
|
||||
|
||||
String String::fromFirstOccurrenceOf (const String& sub,
|
||||
@@ -1882,7 +1884,7 @@ struct StringEncodingConverter
|
||||
const CharPointerType_Dest extraSpace (static_cast <DestChar*> (newSpace));
|
||||
|
||||
#if BEAST_DEBUG // (This just avoids spurious warnings from valgrind about the uninitialised bytes at the end of the buffer..)
|
||||
const size_t bytesToClear = (size_t) bmin ((int) extraBytesNeeded, 4);
|
||||
const size_t bytesToClear = (size_t) std::min ((int) extraBytesNeeded, 4);
|
||||
zeromem (addBytesToPointer (newSpace, extraBytesNeeded - bytesToClear), bytesToClear);
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user