From 10ff2d2156bf72de8f3da0bb642314f9c92812a6 Mon Sep 17 00:00:00 2001 From: Lucian Grijincu Date: Thu, 29 Sep 2016 14:40:13 -0700 Subject: [PATCH] folly: Range: detail::throwOutOfRange -> std::__throw_out_of_range Summary: No need to define our own. Generated code is similar: https://godbolt.org/g/5xWrNx (one extra move instruction). ``` .L20: subq $8, %rsp call S::outOfRange() [clone .isra.0] ``` ``` .LC1: .string "out of range" .L26: subq $8, %rsp movl $.LC1, %edi call std::__throw_out_of_range(char const*) ``` Reviewed By: Orvid Differential Revision: D3945578 fbshipit-source-id: c65e9dea55e8f01f51766b2695af68d2bc92c266 --- folly/Range.h | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/folly/Range.h b/folly/Range.h index 9cacdd58..07e1513f 100644 --- a/folly/Range.h +++ b/folly/Range.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include @@ -145,11 +146,6 @@ struct IsCharPointer { typedef int type; }; -// Prevent it from being inlined to reduce instruction bloat. -FOLLY_NOINLINE inline void throwOutOfRange() { - throw std::out_of_range("index out of range"); -} - } // namespace detail /** @@ -222,7 +218,7 @@ public: template ::const_type = 0> Range(const std::string& str, std::string::size_type startFrom) { if (UNLIKELY(startFrom > str.size())) { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } b_ = str.data() + startFrom; e_ = str.data() + str.size(); @@ -233,7 +229,7 @@ public: std::string::size_type startFrom, std::string::size_type size) { if (UNLIKELY(startFrom > str.size())) { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } b_ = str.data() + startFrom; if (str.size() - startFrom < size) { @@ -256,7 +252,7 @@ public: template ::const_type = 0> Range(const fbstring& str, fbstring::size_type startFrom) { if (UNLIKELY(startFrom > str.size())) { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } b_ = str.data() + startFrom; e_ = str.data() + str.size(); @@ -266,7 +262,7 @@ public: Range(const fbstring& str, fbstring::size_type startFrom, fbstring::size_type size) { if (UNLIKELY(startFrom > str.size())) { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } b_ = str.data() + startFrom; if (str.size() - startFrom < size) { @@ -431,12 +427,12 @@ public: } value_type& at(size_t i) { - if (i >= size()) detail::throwOutOfRange(); + if (i >= size()) std::__throw_out_of_range("index out of range"); return b_[i]; } const value_type& at(size_t i) const { - if (i >= size()) detail::throwOutOfRange(); + if (i >= size()) std::__throw_out_of_range("index out of range"); return b_[i]; } @@ -458,21 +454,21 @@ public: void advance(size_type n) { if (UNLIKELY(n > size())) { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } b_ += n; } void subtract(size_type n) { if (UNLIKELY(n > size())) { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } e_ -= n; } Range subpiece(size_type first, size_type length = npos) const { if (UNLIKELY(first > size())) { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } return Range(b_ + first, std::min(length, size() - first)); @@ -633,7 +629,7 @@ public: } else if (e == e_) { e_ = b; } else { - detail::throwOutOfRange(); + std::__throw_out_of_range("index out of range"); } } -- 2.34.1