1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Get rid of magic numbers

This commit is contained in:
Nobuyoshi Nakada 2022-07-22 10:41:44 +09:00
parent cf7d07570f
commit c6aa65430f
No known key found for this signature in database
GPG key ID: 7CD2805BFA3770C6
Notes: git 2022-07-22 12:01:38 +09:00

View file

@ -145,7 +145,7 @@ static void
dump_append_c(struct dump_config *dc, unsigned char c)
{
if (c <= 0x1f) {
const unsigned int width = (sizeof(c) * CHAR_BIT / 4) + 5;
const unsigned int width = rb_strlen_lit("\\u0000") + 1;
buffer_ensure_capa(dc, width);
unsigned long required = snprintf(dc->buffer + dc->buffer_len, width, "\\u00%02x", c);
RUBY_ASSERT(required <= width);
@ -163,7 +163,7 @@ dump_append_ref(struct dump_config *dc, VALUE ref)
{
RUBY_ASSERT(ref > 0);
char buffer[((sizeof(VALUE) * CHAR_BIT + 3) / 4) + 4];
char buffer[roomof(sizeof(VALUE) * CHAR_BIT, 4) + rb_strlen_lit("\"0x\"")];
char *buffer_start, *buffer_end;
buffer_start = buffer_end = &buffer[sizeof(buffer)];
@ -481,7 +481,8 @@ dump_object(VALUE obj, struct dump_config *dc)
dump_append(dc, ", \"name\":\"");
dump_append(dc, RSTRING_PTR(mod_name));
dump_append(dc, "\"");
} else {
}
else {
VALUE real_mod_name = rb_mod_name(rb_class_real(obj));
if (RTEST(real_mod_name)) {
dump_append(dc, ", \"real_class_name\":\"");
@ -625,7 +626,8 @@ dump_output(struct dump_config *dc, VALUE output, VALUE full, VALUE since)
if (TYPE(output) == T_STRING) {
dc->stream = Qfalse;
dc->string = output;
} else {
}
else {
dc->stream = output;
dc->string = Qfalse;
}
@ -637,7 +639,8 @@ dump_output(struct dump_config *dc, VALUE output, VALUE full, VALUE since)
if (RTEST(since)) {
dc->partial_dump = 1;
dc->since = NUM2SIZET(since);
} else {
}
else {
dc->partial_dump = 0;
}
}
@ -649,7 +652,8 @@ dump_result(struct dump_config *dc)
if (dc->string) {
return dc->string;
} else {
}
else {
rb_io_flush(dc->stream);
return dc->stream;
}