Commit 5b7309d5 authored by Yedidya Feldblum's avatar Yedidya Feldblum Committed by Facebook GitHub Bot

Avoid inlining Cursor slow paths

Summary: [Folly] Avoid inlining `Cursor` slow paths. These are already extracted to separate functions, but the compiler will still aggressively inline them.

Differential Revision: D21392842

fbshipit-source-id: 2b045ae9c5188315b938de984730ad2051237cf5
parent 10eac460
...@@ -710,7 +710,7 @@ class CursorBase { ...@@ -710,7 +710,7 @@ class CursorBase {
return val; return val;
} }
void readFixedStringSlow(std::string* str, size_t len) { FOLLY_NOINLINE void readFixedStringSlow(std::string* str, size_t len) {
for (size_t available; (available = length()) < len;) { for (size_t available; (available = length()) < len;) {
str->append(reinterpret_cast<const char*>(data()), available); str->append(reinterpret_cast<const char*>(data()), available);
if (UNLIKELY(!tryAdvanceBuffer())) { if (UNLIKELY(!tryAdvanceBuffer())) {
...@@ -723,7 +723,7 @@ class CursorBase { ...@@ -723,7 +723,7 @@ class CursorBase {
advanceBufferIfEmpty(); advanceBufferIfEmpty();
} }
size_t pullAtMostSlow(void* buf, size_t len) { FOLLY_NOINLINE size_t pullAtMostSlow(void* buf, size_t len) {
// If the length of this buffer is 0 try advancing it. // If the length of this buffer is 0 try advancing it.
// Otherwise on the first iteration of the following loop memcpy is called // Otherwise on the first iteration of the following loop memcpy is called
// with a null source pointer. // with a null source pointer.
...@@ -747,13 +747,13 @@ class CursorBase { ...@@ -747,13 +747,13 @@ class CursorBase {
return copied + len; return copied + len;
} }
void pullSlow(void* buf, size_t len) { FOLLY_NOINLINE void pullSlow(void* buf, size_t len) {
if (UNLIKELY(pullAtMostSlow(buf, len) != len)) { if (UNLIKELY(pullAtMostSlow(buf, len) != len)) {
throw_exception<std::out_of_range>("underflow"); throw_exception<std::out_of_range>("underflow");
} }
} }
size_t skipAtMostSlow(size_t len) { FOLLY_NOINLINE size_t skipAtMostSlow(size_t len) {
size_t skipped = 0; size_t skipped = 0;
for (size_t available; (available = length()) < len;) { for (size_t available; (available = length()) < len;) {
skipped += available; skipped += available;
...@@ -767,13 +767,13 @@ class CursorBase { ...@@ -767,13 +767,13 @@ class CursorBase {
return skipped + len; return skipped + len;
} }
void skipSlow(size_t len) { FOLLY_NOINLINE void skipSlow(size_t len) {
if (UNLIKELY(skipAtMostSlow(len) != len)) { if (UNLIKELY(skipAtMostSlow(len) != len)) {
throw_exception<std::out_of_range>("underflow"); throw_exception<std::out_of_range>("underflow");
} }
} }
size_t retreatAtMostSlow(size_t len) { FOLLY_NOINLINE size_t retreatAtMostSlow(size_t len) {
size_t retreated = 0; size_t retreated = 0;
for (size_t available; (available = crtPos_ - crtBegin_) < len;) { for (size_t available; (available = crtPos_ - crtBegin_) < len;) {
retreated += available; retreated += available;
...@@ -786,7 +786,7 @@ class CursorBase { ...@@ -786,7 +786,7 @@ class CursorBase {
return retreated + len; return retreated + len;
} }
void retreatSlow(size_t len) { FOLLY_NOINLINE void retreatSlow(size_t len) {
if (UNLIKELY(retreatAtMostSlow(len) != len)) { if (UNLIKELY(retreatAtMostSlow(len) != len)) {
throw_exception<std::out_of_range>("underflow"); throw_exception<std::out_of_range>("underflow");
} }
......
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