folly: Range: detail::throwOutOfRange -> std::__throw_out_of_range
authorLucian Grijincu <lucian@fb.com>
Thu, 29 Sep 2016 21:40:13 +0000 (14:40 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Thu, 29 Sep 2016 21:53:26 +0000 (14:53 -0700)
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

index 9cacdd58877c1693c295ebb63e0c9653f3058a44..07e1513f72f655ad5028b7d420ad2c089c941d4f 100644 (file)
@@ -22,6 +22,7 @@
 #include <folly/FBString.h>
 #include <folly/Portability.h>
 #include <folly/SpookyHashV2.h>
+#include <folly/portability/BitsFunctexcept.h>
 #include <folly/portability/Constexpr.h>
 #include <folly/portability/String.h>
 
@@ -145,11 +146,6 @@ struct IsCharPointer<const char*> {
   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 <class T = Iter, typename detail::IsCharPointer<T>::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 <class T = Iter, typename detail::IsCharPointer<T>::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");
     }
   }