diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-12-09 01:14:43 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2022-12-09 22:11:44 +0900 |
commit | 11acb7f7bcf6e80e03cf83bba863b9b3f980fdca (patch) | |
tree | 4df39298309958cc2cc04b2e1296260268db664a /sprintf.c | |
parent | 181d4bee5e03a30596e78b2d7aa0396887a53881 (diff) |
[Bug #19167] Remove useless conversion of classes for special const
Diffstat (limited to 'sprintf.c')
-rw-r--r-- | sprintf.c | 26 |
1 files changed, 8 insertions, 18 deletions
@@ -1106,26 +1106,16 @@ ruby__sfvextra(rb_printf_buffer *fp, size_t valsize, void *valp, long *sz, int s rb_raise(rb_eRuntimeError, "rb_vsprintf reentered"); } if (sign == '+') { - if (RB_TYPE_P(value, T_CLASS)) { # define LITERAL(str) (*sz = rb_strlen_lit(str), str) - - if (value == rb_cNilClass) { - return LITERAL("nil"); - } - else if (value == rb_cInteger) { - return LITERAL("Integer"); - } - else if (value == rb_cSymbol) { - return LITERAL("Symbol"); - } - else if (value == rb_cTrueClass) { - return LITERAL("true"); - } - else if (value == rb_cFalseClass) { - return LITERAL("false"); - } -# undef LITERAL + /* optimize special const cases */ + switch (value) { +# define LITERAL_CASE(x) case Q##x: return LITERAL(#x) + LITERAL_CASE(nil); + LITERAL_CASE(true); + LITERAL_CASE(false); +# undef LITERAL_CASE } +# undef LITERAL value = rb_inspect(value); } else if (SYMBOL_P(value)) { |