[Bug #19167] Remove useless conversion of classes for special const

This commit is contained in:
Nobuyoshi Nakada 2022-12-09 01:14:43 +09:00
parent 181d4bee5e
commit 11acb7f7bc
No known key found for this signature in database
GPG Key ID: 7CD2805BFA3770C6
2 changed files with 13 additions and 21 deletions

View File

@ -1040,10 +1040,12 @@ end
@s.rb_sprintf3(true.class).should == s
end
ruby_bug "#19167", ""..."3.2" do
it "formats a TrueClass VALUE as 'true' if sign specified in format" do
s = 'Result: true.'
s = 'Result: TrueClass.'
@s.rb_sprintf4(true.class).should == s
end
end
it "truncates a string to a supplied precision if that is shorter than the string" do
s = 'Result: Hel.'

View File

@ -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");
/* 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)) {