Minor optimizations to cmd_print.c ##refactor (#17896)

This commit is contained in:
Liumeo 2020-11-26 03:33:01 -05:00 committed by GitHub
parent f18e431287
commit 1c443d056a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -6859,7 +6859,6 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se
char space[32] = {
0
};
const char *white;
const char *reset = p->resetbg? Color_RESET: Color_RESET_NOBG;
bool show_color = p->flags & R_PRINT_FLAGS_COLOR;
if (show_color) {
@ -6872,13 +6871,12 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se
if (offseg) {
ut32 s, a;
a = off & 0xffff;
s = (off - a) >> seggrn;
s = ((off - a) >> seggrn) & 0xffff;
if (offdec) {
snprintf (space, sizeof (space), "%d:%d", s & 0xffff, a & 0xffff);
white = r_str_pad (' ', 9 - strlen (space));
r_cons_printf ("%s%s%s%s%s", k, inv, white, space, reset);
snprintf (space, sizeof (space), "%d:%d", s, a);
r_cons_printf ("%s%s%9s%s", k, inv, space, reset);
} else {
r_cons_printf ("%s%s%04x:%04x%s", k, inv, s & 0xFFFF, a & 0xFFFF, reset);
r_cons_printf ("%s%s%04x:%04x%s", k, inv, s, a, reset);
}
} else {
int sz = lenof (off, 0);
@ -6887,11 +6885,10 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se
if (label) {
const int label_padding = 10;
if (delta > 0) {
const char *pad = r_str_pad (' ', sz - sz2 + label_padding);
if (offdec) {
const char *pad = r_str_pad (' ', sz - sz2 + label_padding);
r_cons_printf ("%s%s%s%s+%d%s", k, inv, label, reset, delta, pad);
} else {
const char *pad = r_str_pad (' ', sz - sz2 + label_padding);
r_cons_printf ("%s%s%s%s+0x%x%s", k, inv, label, reset, delta, pad);
}
} else {
@ -6909,8 +6906,7 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se
} else {
if (offdec) {
snprintf (space, sizeof (space), "%"PFMT64u, off);
white = r_str_pad (' ', 10 - strlen (space));
r_cons_printf ("%s%s%s%s%s", k, inv, white, space, reset);
r_cons_printf ("%s%s%10s%s", k, inv, space, reset);
} else {
if (p->wide_offsets) {
r_cons_printf ("%s%s0x%016"PFMT64x "%s", k, inv, off, reset);
@ -6928,8 +6924,7 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se
s = (off - a) >> seggrn;
if (offdec) {
snprintf (space, sizeof (space), "%d:%d", s & 0xffff, a & 0xffff);
white = r_str_pad (' ', 9 - strlen (space));
r_cons_printf ("%s%s%s", white, space, reset);
r_cons_printf ("%9s%s", space, reset);
} else {
r_cons_printf ("%04x:%04x", s & 0xFFFF, a & 0xFFFF);
}
@ -6946,8 +6941,7 @@ R_API void r_print_offset_sg(RPrint *p, ut64 off, int invert, int offseg, int se
} else {
if (offdec) {
snprintf (space, sizeof (space), "%"PFMT64u, off);
white = r_str_pad (' ', 10 - strlen (space));
r_cons_printf ("%s%s", white, space);
r_cons_printf ("%10s", space);
} else {
r_cons_printf ("0x%08"PFMT64x " ", off);
}