diff options
author | Kenta Murata <[email protected]> | 2021-01-01 04:13:12 +0900 |
---|---|---|
committer | Kenta Murata <[email protected]> | 2021-01-02 00:54:09 +0900 |
commit | 448a67cd812d0be0a7f1cc871daa598c3b846143 (patch) | |
tree | 95c627713f6b2129787d60731d57f0f26c0e8d04 /ext/bigdecimal/static_assert.h | |
parent | 4730efdd80f40119f8a397fe1b4b7ba88a0ce3d3 (diff) |
[ruby/bigdecimal] Implement special conversions for 64-bit integers
This change improves the conversion speed from small integers.
```
Comparison:
big_n9
master: 4003688.9 i/s
bigdecimal 3.0.0: 1270551.0 i/s - 3.15x slower
big_n19
master: 5410096.4 i/s
bigdecimal 3.0.0: 1000250.3 i/s - 5.41x slower
```
https://github.com/ruby/bigdecimal/commit/3429bd7e6f
Diffstat (limited to 'ext/bigdecimal/static_assert.h')
-rw-r--r-- | ext/bigdecimal/static_assert.h | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ext/bigdecimal/static_assert.h b/ext/bigdecimal/static_assert.h new file mode 100644 index 0000000000..9295729bf6 --- /dev/null +++ b/ext/bigdecimal/static_assert.h @@ -0,0 +1,54 @@ +#ifndef BIGDECIMAL_STATIC_ASSERT_H +#define BIGDECIMAL_STATIC_ASSERT_H + +#include "feature.h" + +#ifdef HAVE_RUBY_INTERNAL_STATIC_ASSERT_H +# include <ruby/internal/static_assert.h> +#endif + +#ifdef RBIMPL_STATIC_ASSERT +# define STATIC_ASSERT RBIMPL_STATIC_ASSERT +#endif + +#ifndef STATIC_ASSERT +# /* The following section is copied from CRuby's static_assert.h */ + +# if defined(__cplusplus) && defined(__cpp_static_assert) +# /* https://isocpp.org/std/standing-documents/sd-6-sg10-feature-test-recommendations */ +# define BIGDECIMAL_STATIC_ASSERT0 static_assert + +# elif defined(__cplusplus) && defined(_MSC_VER) && _MSC_VER >= 1600 +# define BIGDECIMAL_STATIC_ASSERT0 static_assert + +# elif defined(__INTEL_CXX11_MODE__) +# define BIGDECIMAL_STATIC_ASSERT0 static_assert + +# elif defined(__cplusplus) && __cplusplus >= 201103L +# define BIGDECIMAL_STATIC_ASSERT0 static_assert + +# elif defined(__cplusplus) && __has_extension(cxx_static_assert) +# define BIGDECIMAL_STATIC_ASSERT0 __extension__ static_assert + +# elif defined(__STDC_VERSION__) && __has_extension(c_static_assert) +# define BIGDECIMAL_STATIC_ASSERT0 __extension__ _Static_assert + +# elif defined(__STDC_VERSION__) && defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) +# define BIGDECIMAL_STATIC_ASSERT0 __extension__ _Static_assert +#endif + +# if defined(__DOXYGEN__) +# define STATIC_ASSERT static_assert + +# elif defined(BIGDECIMAL_STATIC_ASSERT0) +# define STATIC_ASSERT(name, expr) \ + BIGDECIMAL_STATIC_ASSERT0(expr, #name ": " #expr) + +# else +# define STATIC_ASSERT(name, expr) \ + typedef int static_assert_ ## name ## _check[1 - 2 * !(expr)] +# endif +#endif /* STATIC_ASSERT */ + + +#endif /* BIGDECIMAL_STATIC_ASSERT_H */ |