summaryrefslogtreecommitdiff
path: root/sprintf.c
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-09 01:14:43 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2022-12-09 22:11:44 +0900
commit11acb7f7bcf6e80e03cf83bba863b9b3f980fdca (patch)
tree4df39298309958cc2cc04b2e1296260268db664a /sprintf.c
parent181d4bee5e03a30596e78b2d7aa0396887a53881 (diff)
[Bug #19167] Remove useless conversion of classes for special const
Diffstat (limited to 'sprintf.c')
-rw-r--r--sprintf.c26
1 files changed, 8 insertions, 18 deletions
diff --git a/sprintf.c b/sprintf.c
index b26dffec85..b2d89617aa 100644
--- a/sprintf.c
+++ b/sprintf.c
@@ -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)) {