Commit 2ff9d181 authored by Giuseppe Ottaviano's avatar Giuseppe Ottaviano Committed by Facebook Github Bot

Outline several fbstring/malloc functions

Summary: Outline all the non-trivial constructor and the destructor, `assign()`, and `append()` to reduce code size. The fast path of copy, and moves, are instead still inlined.

Reviewed By: philippv

Differential Revision: D3896612

fbshipit-source-id: 25050d4ba28d25da226a7bc49d5b542947d0c512
parent 471f03d0
This diff is collapsed.
...@@ -111,6 +111,7 @@ __attribute__((__weak__)); ...@@ -111,6 +111,7 @@ __attribute__((__weak__));
#include <cstdlib> #include <cstdlib>
#include <cstring> #include <cstring>
#include <atomic>
#include <new> #include <new>
#ifdef _LIBSTDCXX_FBSTRING #ifdef _LIBSTDCXX_FBSTRING
...@@ -121,17 +122,21 @@ namespace folly { ...@@ -121,17 +122,21 @@ namespace folly {
#endif #endif
// Cannot depend on Portability.h when _LIBSTDCXX_FBSTRING. // Cannot depend on Portability.h when _LIBSTDCXX_FBSTRING.
// Disabled for nvcc because it fails on attributes on lambdas. #if defined(__GNUC__)
#if defined(__GNUC__) && !defined(__NVCC__)
#define FOLLY_MALLOC_NOINLINE __attribute__((__noinline__)) #define FOLLY_MALLOC_NOINLINE __attribute__((__noinline__))
// This is for checked malloc-like functions (returns non-null pointer
// which cannot alias any outstanding pointer).
#define FOLLY_MALLOC_CHECKED_MALLOC \
__attribute__((__returns_nonnull__, __malloc__))
#else #else
#define FOLLY_MALLOC_NOINLINE #define FOLLY_MALLOC_NOINLINE
#define FOLLY_MALLOC_CHECKED_MALLOC
#endif #endif
/** /**
* Determine if we are using jemalloc or not. * Determine if we are using jemalloc or not.
*/ */
inline bool usingJEMalloc() noexcept { FOLLY_MALLOC_NOINLINE inline bool usingJEMalloc() noexcept {
// Checking for rallocx != NULL is not sufficient; we may be in a dlopen()ed // Checking for rallocx != NULL is not sufficient; we may be in a dlopen()ed
// module that depends on libjemalloc, so rallocx is resolved, but the main // module that depends on libjemalloc, so rallocx is resolved, but the main
// program might be using a different memory allocator. // program might be using a different memory allocator.
...@@ -140,7 +145,7 @@ inline bool usingJEMalloc() noexcept { ...@@ -140,7 +145,7 @@ inline bool usingJEMalloc() noexcept {
// per-thread counter of allocated memory increases. This makes me // per-thread counter of allocated memory increases. This makes me
// feel dirty inside. Also note that this requires jemalloc to have // feel dirty inside. Also note that this requires jemalloc to have
// been compiled with --enable-stats. // been compiled with --enable-stats.
static const bool result = [] () FOLLY_MALLOC_NOINLINE noexcept { static const bool result = [] () noexcept {
// Some platforms (*cough* OSX *cough*) require weak symbol checks to be // Some platforms (*cough* OSX *cough*) require weak symbol checks to be
// in the form if (mallctl != nullptr). Not if (mallctl) or if (!mallctl) // in the form if (mallctl != nullptr). Not if (mallctl) or if (!mallctl)
// (!!). http://goo.gl/xpmctm // (!!). http://goo.gl/xpmctm
...@@ -235,7 +240,8 @@ inline void* checkedRealloc(void* ptr, size_t size) { ...@@ -235,7 +240,8 @@ inline void* checkedRealloc(void* ptr, size_t size) {
* routine just tries to call realloc() (thus benefitting of potential * routine just tries to call realloc() (thus benefitting of potential
* copy-free coalescing) unless there's too much slack memory. * copy-free coalescing) unless there's too much slack memory.
*/ */
inline void* smartRealloc(void* p, FOLLY_MALLOC_CHECKED_MALLOC FOLLY_MALLOC_NOINLINE inline void* smartRealloc(
void* p,
const size_t currentSize, const size_t currentSize,
const size_t currentCapacity, const size_t currentCapacity,
const size_t newCapacity) { const size_t newCapacity) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment