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