proxygen
|
#include <FBString.h>
Classes | |
struct | MediumLarge |
struct | RefCounted |
Public Member Functions | |
fbstring_core () noexcept | |
fbstring_core (const fbstring_core &rhs) | |
fbstring_core (fbstring_core &&goner) noexcept | |
fbstring_core (const Char *const data, const size_t size, bool disableSSO=false) | |
~fbstring_core () noexcept | |
fbstring_core (Char *const data, const size_t size, const size_t allocatedSize, AcquireMallocatedString) | |
void | swap (fbstring_core &rhs) |
const Char * | data () const |
Char * | mutableData () |
const Char * | c_str () const |
void | shrink (const size_t delta) |
FOLLY_MALLOC_NOINLINE void | reserve (size_t minCapacity, bool disableSSO=false) |
Char * | expandNoinit (const size_t delta, bool expGrowth=false, bool disableSSO=false) |
void | push_back (Char c) |
size_t | size () const |
size_t | capacity () const |
bool | isShared () const |
Static Protected Attributes | |
static constexpr auto | kIsLittleEndian |
Private Types | |
enum | Category : category_type { Category::isSmall = 0, Category::isMedium = kIsLittleEndian ? 0x80 : 0x2, Category::isLarge = kIsLittleEndian ? 0x40 : 0x1 } |
typedef uint8_t | category_type |
Private Member Functions | |
fbstring_core & | operator= (const fbstring_core &rhs) |
void | reset () |
FOLLY_MALLOC_NOINLINE void | destroyMediumLarge () noexcept |
Category | category () const |
size_t | smallSize () const |
void | setSmallSize (size_t s) |
void | copySmall (const fbstring_core &) |
void | copyMedium (const fbstring_core &) |
void | copyLarge (const fbstring_core &) |
void | initSmall (const Char *data, size_t size) |
void | initMedium (const Char *data, size_t size) |
void | initLarge (const Char *data, size_t size) |
void | reserveSmall (size_t minCapacity, bool disableSSO) |
void | reserveMedium (size_t minCapacity) |
void | reserveLarge (size_t minCapacity) |
void | shrinkSmall (size_t delta) |
void | shrinkMedium (size_t delta) |
void | shrinkLarge (size_t delta) |
void | unshare (size_t minCapacity=0) |
Char * | mutableDataLarge () |
Private Attributes | |
union { | |
uint8_t bytes_ [sizeof(MediumLarge)] | |
Char small_ [sizeof(MediumLarge)/sizeof(Char)] | |
MediumLarge ml_ | |
}; | |
Static Private Attributes | |
static constexpr size_t | lastChar = sizeof(MediumLarge) - 1 |
static constexpr size_t | maxSmallSize = lastChar / sizeof(Char) |
static constexpr size_t | maxMediumSize = 254 / sizeof(Char) |
static constexpr uint8_t | categoryExtractMask = kIsLittleEndian ? 0xC0 : 0x3 |
static constexpr size_t | kCategoryShift = (sizeof(size_t) - 1) * 8 |
static constexpr size_t | capacityExtractMask |
This is the core of the string. The code should work on 32- and 64-bit and both big- and little-endianan architectures with any Char size.
The storage is selected as follows (assuming we store one-byte characters on a 64-bit machine): (a) "small" strings between 0 and 23 chars are stored in-situ without allocation (the rightmost byte stores the size); (b) "medium" strings from 24 through 254 chars are stored in malloc-allocated memory that is copied eagerly; (c) "large" strings of 255 chars and above are stored in a similar structure as medium arrays, except that the string is reference-counted and copied lazily. the reference count is allocated right before the character array.
The discriminator between these three strategies sits in two bits of the rightmost char of the storage:
maxSmallSize - size
, so this quantity must be subtracted from maxSmallSize
to compute the size
of the string (see smallSize()
). This scheme ensures that when size ==
maxSmallSize`, the last byte in the storage is \0. This way, storage will be a null-terminated sequence of bytes, even if all 23 bytes of data are used on a 64-bit architecture. This enables c_str()
and data()
to simply return a pointer to the storage.Definition at line 327 of file FBString.h.
|
private |
Definition at line 619 of file FBString.h.
|
strongprivate |
Enumerator | |
---|---|
isSmall | |
isMedium | |
isLarge |
Definition at line 621 of file FBString.h.
|
inlinenoexcept |
Definition at line 341 of file FBString.h.
|
inline |
Definition at line 345 of file FBString.h.
|
inlinenoexcept |
Definition at line 364 of file FBString.h.
|
inline |
Definition at line 371 of file FBString.h.
|
inlinenoexcept |
Definition at line 387 of file FBString.h.
|
inline |
Definition at line 401 of file FBString.h.
|
inline |
Definition at line 448 of file FBString.h.
|
inline |
|
inlineprivate |
Definition at line 627 of file FBString.h.
Referenced by folly::fbstring_core< char >::fbstring_core().
|
inlineprivate |
Definition at line 741 of file FBString.h.
References FBSTRING_ASSERT, folly::fbstring_core< Char >::ml_, folly::size(), and folly::fbstring_core< Char >::size().
|
inlineprivate |
Definition at line 726 of file FBString.h.
References testing::gmock_generated_actions_test::Char(), folly::checkedMalloc(), folly::fbstring_core< Char >::MediumLarge::data_, FBSTRING_ASSERT, folly::goodMallocSize(), folly::fbstring_core< Char >::ml_, folly::fbstring_detail::podCopy(), and folly::fbstring_core< Char >::MediumLarge::size_.
|
inlineprivate |
Definition at line 707 of file FBString.h.
References data_, FBSTRING_ASSERT, folly::fbstring_core< Char >::ml_, folly::size(), and folly::fbstring_core< Char >::size().
|
inline |
Definition at line 432 of file FBString.h.
Referenced by folly::fbstring_core< char >::fbstring_core().
|
inlineprivatenoexcept |
Definition at line 539 of file FBString.h.
|
inline |
Definition at line 943 of file FBString.h.
References FBSTRING_ASSERT, FBSTRING_LIKELY, FBSTRING_UNLIKELY, max, reserve(), and folly::size().
|
inlineprivate |
Definition at line 814 of file FBString.h.
References folly::size().
|
inlineprivate |
Definition at line 798 of file FBString.h.
References testing::gmock_generated_actions_test::Char(), folly::checkedMalloc(), FBSTRING_LIKELY, folly::goodMallocSize(), folly::fbstring_detail::podCopy(), and folly::size().
|
inlineprivate |
Definition at line 751 of file FBString.h.
References testing::gmock_generated_actions_test::Char(), data, FOLLY_FALLTHROUGH, and folly::fbstring_detail::podCopy().
|
inline |
Definition at line 527 of file FBString.h.
|
inline |
Definition at line 436 of file FBString.h.
|
inlineprivate |
|
private |
|
inline |
Definition at line 489 of file FBString.h.
|
inline |
Definition at line 467 of file FBString.h.
Referenced by folly::fbstring_core< Char >::reserveMedium().
|
inlineprivate |
Definition at line 853 of file FBString.h.
References FBSTRING_ASSERT, and refs.
|
inlineprivate |
Definition at line 877 of file FBString.h.
References testing::gmock_generated_actions_test::Char(), folly::fbstring_core< Char >::MediumLarge::data_, FBSTRING_ASSERT, folly::goodMallocSize(), folly::fbstring_core< Char >::ml_, folly::fbstring_detail::podCopy(), folly::fbstring_core< Char >::reserve(), folly::fbstring_core< Char >::MediumLarge::size_, folly::smartRealloc(), and folly::fbstring_core< Char >::swap().
|
inlineprivate |
Definition at line 910 of file FBString.h.
References testing::gmock_generated_actions_test::Char(), folly::checkedMalloc(), FBSTRING_ASSERT, folly::goodMallocSize(), folly::fbstring_detail::podCopy(), and folly::size().
|
inlineprivate |
Definition at line 535 of file FBString.h.
|
inlineprivate |
Definition at line 675 of file FBString.h.
|
inline |
Definition at line 455 of file FBString.h.
|
inlineprivate |
Definition at line 994 of file FBString.h.
References FBSTRING_ASSERT, and folly::fbstring_core< Char >::swap().
|
inlineprivate |
|
inlineprivate |
|
inline |
Definition at line 493 of file FBString.h.
Referenced by folly::fbstring_core< Char >::copyLarge(), folly::fbstring_core< Char >::copySmall(), folly::fbstring_core< char >::fbstring_core(), and folly::operator+().
|
inlineprivate |
Definition at line 667 of file FBString.h.
|
inline |
Definition at line 425 of file FBString.h.
Referenced by folly::fbstring_core< Char >::reserveMedium(), and folly::fbstring_core< Char >::shrinkLarge().
|
inlineprivate |
Definition at line 827 of file FBString.h.
References FBSTRING_ASSERT, max, and folly::fbstring_detail::podCopy().
union { ... } |
uint8_t folly::fbstring_core< Char >::bytes_[sizeof(MediumLarge)] |
Definition at line 649 of file FBString.h.
|
staticprivate |
Definition at line 659 of file FBString.h.
|
staticprivate |
Definition at line 657 of file FBString.h.
|
staticprivate |
Definition at line 658 of file FBString.h.
|
staticprotected |
Definition at line 337 of file FBString.h.
|
staticprivate |
Definition at line 654 of file FBString.h.
|
staticprivate |
Definition at line 656 of file FBString.h.
|
staticprivate |
Definition at line 655 of file FBString.h.
MediumLarge folly::fbstring_core< Char >::ml_ |
Definition at line 651 of file FBString.h.
Referenced by folly::fbstring_core< Char >::copyLarge(), folly::fbstring_core< Char >::copyMedium(), folly::fbstring_core< Char >::copySmall(), folly::fbstring_core< Char >::reserveMedium(), and folly::fbstring_core< char >::swap().
Char folly::fbstring_core< Char >::small_[sizeof(MediumLarge)/sizeof(Char)] |
Definition at line 650 of file FBString.h.