@@ -65,6 +65,7 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
65
65
#include " strmake.h"
66
66
#include " strxmov.h"
67
67
#include " strxnmov.h"
68
+ #include " template_utils.h"
68
69
#include " typelib.h"
69
70
#include " violite.h"
70
71
@@ -3941,14 +3942,28 @@ static bool is_binary_field(MYSQL_FIELD *field) {
3941
3942
3942
3943
static void print_as_hex (FILE *output_file, const char *str, ulong len,
3943
3944
ulong total_bytes_to_send) {
3944
- const char *ptr = str, *end = ptr + len;
3945
+ const unsigned char *ptr = pointer_cast<const unsigned char *>(str);
3946
+ const unsigned char *end = ptr + len;
3945
3947
ulong i;
3946
3948
3947
3949
if (str != nullptr ) {
3948
3950
fprintf (output_file, " 0x" );
3949
- for (; ptr < end; ptr++)
3950
- fprintf (output_file, " %02X" ,
3951
- *(static_cast <const uchar *>(static_cast <const void *>(ptr))));
3951
+ ulong remaining = len;
3952
+ static const unsigned char hex_digits[] = " 0123456789ABCDEF" ;
3953
+ unsigned char chunk_buf[64 ];
3954
+ while (ptr < end) {
3955
+ // write up to 32 input bytes at a time for performance
3956
+ // (up to 64 bytes of hex output)
3957
+ const size_t chunk_input_size = std::min ((uint )remaining, 32U );
3958
+ for (size_t j = 0 ; j < chunk_input_size; j++) {
3959
+ const size_t offset = 2 * j;
3960
+ chunk_buf[offset] = hex_digits[(*ptr >> 4 ) & 0x0F ];
3961
+ chunk_buf[offset + 1 ] = hex_digits[(*ptr) & 0x0F ];
3962
+ ptr++;
3963
+ }
3964
+ fwrite (chunk_buf, 1 , 2 * chunk_input_size, output_file);
3965
+ remaining -= chunk_input_size;
3966
+ }
3952
3967
/* Printed string length: two chars "0x" + two chars for each byte. */
3953
3968
i = 2 + len * 2 ;
3954
3969
} else {
@@ -4005,11 +4020,13 @@ static void print_table_data(MYSQL_RES *result) {
4005
4020
tee_puts (separator.ptr (), PAGER);
4006
4021
}
4007
4022
4023
+ const uint num_fields = mysql_num_fields (result);
4024
+
4008
4025
while ((cur = mysql_fetch_row (result))) {
4009
4026
ulong *lengths = mysql_fetch_lengths (result);
4010
4027
(void )tee_fputs (" | " , PAGER);
4011
4028
mysql_field_seek (result, 0 );
4012
- for (uint off = 0 ; off < mysql_num_fields (result) ; off++) {
4029
+ for (uint off = 0 ; off < num_fields ; off++) {
4013
4030
const char *buffer;
4014
4031
uint data_length;
4015
4032
uint field_max_length;
@@ -4029,31 +4046,33 @@ static void print_table_data(MYSQL_RES *result) {
4029
4046
field = mysql_fetch_field (result);
4030
4047
field_max_length = field->max_length ;
4031
4048
4032
- /*
4033
- How many text cells on the screen will this string span? If it
4034
- contains multibyte characters, then the number of characters we occupy
4035
- on screen will be fewer than the number of bytes we occupy in memory.
4036
-
4037
- We need to find how much screen real-estate we will occupy to know how
4038
- many extra padding-characters we should send with the printing
4039
- function.
4040
- */
4041
- visible_length = charset_info->cset ->numcells (charset_info, buffer,
4042
- buffer + data_length);
4043
- extra_padding = (uint )(data_length - visible_length);
4044
-
4045
4049
if (opt_binhex && is_binary_field (field))
4046
4050
print_as_hex (PAGER, cur[off], lengths[off], field_max_length);
4047
- else if (field_max_length > MAX_COLUMN_LENGTH)
4048
- tee_print_sized_data (buffer, data_length,
4049
- MAX_COLUMN_LENGTH + extra_padding, false );
4050
4051
else {
4051
- if (num_flag[off] != 0 ) /* if it is numeric, we right-justify it */
4052
- tee_print_sized_data (buffer, data_length,
4053
- field_max_length + extra_padding, true );
4054
- else
4052
+ /*
4053
+ How many text cells on the screen will this string span? If it
4054
+ contains multibyte characters, then the number of characters we occupy
4055
+ on screen will be fewer than the number of bytes we occupy in memory.
4056
+
4057
+ We need to find how much screen real-estate we will occupy to know how
4058
+ many extra padding-characters we should send with the printing
4059
+ function.
4060
+ */
4061
+ visible_length = charset_info->cset ->numcells (charset_info, buffer,
4062
+ buffer + data_length);
4063
+ extra_padding = (uint )(data_length - visible_length);
4064
+
4065
+ if (field_max_length > MAX_COLUMN_LENGTH)
4055
4066
tee_print_sized_data (buffer, data_length,
4056
- field_max_length + extra_padding, false );
4067
+ MAX_COLUMN_LENGTH + extra_padding, false );
4068
+ else {
4069
+ if (num_flag[off] != 0 ) /* if it is numeric, we right-justify it */
4070
+ tee_print_sized_data (buffer, data_length,
4071
+ field_max_length + extra_padding, true );
4072
+ else
4073
+ tee_print_sized_data (buffer, data_length,
4074
+ field_max_length + extra_padding, false );
4075
+ }
4057
4076
}
4058
4077
tee_fputs (" |" , PAGER);
4059
4078
}
@@ -5519,13 +5538,14 @@ void tee_write(FILE *file, const char *s, size_t slen, int flags) {
5519
5538
#ifdef _WIN32
5520
5539
const bool is_console = my_win_is_console_cached (file);
5521
5540
#endif
5541
+ const bool is_mb = use_mb (charset_info);
5522
5542
const char *se;
5523
5543
for (se = s + slen; s < se; s++) {
5524
5544
const char *t;
5525
5545
5526
5546
if (flags & MY_PRINT_MB) {
5527
5547
int mblen ;
5528
- if (use_mb (charset_info) && (mblen = my_ismbchar (charset_info, s, se))) {
5548
+ if (is_mb && (mblen = my_ismbchar (charset_info, s, se))) {
5529
5549
#ifdef _WIN32
5530
5550
if (is_console)
5531
5551
my_win_console_write (charset_info, s, mblen );
0 commit comments