folly: use std::__throw_out_of_range
authorLucian Grijincu <lucian@fb.com>
Fri, 30 Sep 2016 19:12:32 +0000 (12:12 -0700)
committerFacebook Github Bot <facebook-github-bot-bot@fb.com>
Fri, 30 Sep 2016 19:23:29 +0000 (12:23 -0700)
commiteb6bd53fde2fd971d891c06fa81f8d0e385a79a1
tree2e53d0201aba08d990f9b40fdcdd59be698a1043
parentfc8025b463cbd1a167d68c49e74e93a158b2bf03
folly: use std::__throw_out_of_range

Summary:
A ton of these functions are tiny and should be inlined. `throw std::out_of_range("bla")` generates quite a lot of code.

See godbolt from {D3940968}: https://godbolt.org/g/9K36Km

  advanceNoInline(S):
          movq    %rdi, %rax
          sarq    $32, %rax
          cmpl    %eax, %edi
          jg      .L20
          leal    1(%rdi), %eax
          ret
  .L20:
          subq    $8, %rsp
          call    S::outOfRange() [clone .isra.0]

vs previous implementation

  advance(S):
          movq    %rdi, %rdx
          sarq    $32, %rdx
          cmpl    %edx, %edi
          jg      .L14
          leal    1(%rdi), %eax
          ret
  .L14:
          pushq   %rbp
          pushq   %rbx
          movl    $16, %edi
          subq    $8, %rsp
          call    __cxa_allocate_exception
          movl    $.LC0, %esi
          movq    %rax, %rdi
          movq    %rax, %rbx
          call    std::out_of_range::out_of_range(char const*)
          movl    std::out_of_range::~out_of_range(), %edx
          movl    typeinfo for std::out_of_range, %esi
          movq    %rbx, %rdi
          call    __cxa_throw
          movq    %rax, %rbp
          movq    %rbx, %rdi
          call    __cxa_free_exception
          movq    %rbp, %rdi
          call    _Unwind_Resume

This pattern is in the standard library as well:
```
      reference
      at(size_type __n)
      {
if (__n >= _Nm)
  std::__throw_out_of_range(__N("array::at"));
return _M_instance[__n];
      }
```

https://github.com/gcc-mirror/gcc/blob/edd716b6b1caa1a5cb320a8cd7f626f30198e098/libstdc%2B%2B-v3/include/tr1/array#L138

Reviewed By: yfeldblum

Differential Revision: D3947075

fbshipit-source-id: 6e174c725791762a533a534c8482ea9576460b86
folly/EvictingCacheMap.h
folly/FBVector.h
folly/dynamic.cpp
folly/io/Cursor-inl.h
folly/io/Cursor.h
folly/small_vector.h
folly/sorted_vector_types.h