Skip to content

Commit 86d3898

Browse files
committed
objstrunicode: Get rid of bytes checking, it's separate type.
1 parent d215ee1 commit 86d3898

1 file changed

Lines changed: 7 additions & 15 deletions

File tree

py/objstrunicode.c

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ STATIC mp_obj_t mp_obj_new_str_iterator(mp_obj_t str);
4747
/******************************************************************************/
4848
/* str */
4949

50-
STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len, bool is_bytes) {
50+
STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), void *env, const byte *str_data, uint str_len) {
5151
// this escapes characters, but it will be very slow to print (calling print many times)
5252
bool has_single_quote = false;
5353
bool has_double_quote = false;
@@ -66,12 +66,8 @@ STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), voi
6666
const char *s = (const char *)str_data, *top = (const char *)str_data + str_len;
6767
while (s < top) {
6868
unichar ch;
69-
if (is_bytes) {
70-
ch = *(unsigned char *)s++; // Don't sign-extend bytes
71-
} else {
72-
ch = utf8_get_char(s);
73-
s = utf8_next_char(s);
74-
}
69+
ch = utf8_get_char(s);
70+
s = utf8_next_char(s);
7571
if (ch == quote_char) {
7672
print(env, "\\%c", quote_char);
7773
} else if (ch == '\\') {
@@ -95,16 +91,12 @@ STATIC void uni_print_quoted(void (*print)(void *env, const char *fmt, ...), voi
9591
print(env, "%c", quote_char);
9692
}
9793

98-
STATIC void str_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
94+
STATIC void uni_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
9995
GET_STR_DATA_LEN(self_in, str_data, str_len);
100-
bool is_bytes = MP_OBJ_IS_TYPE(self_in, &mp_type_bytes);
101-
if (kind == PRINT_STR && !is_bytes) {
96+
if (kind == PRINT_STR) {
10297
print(env, "%.*s", str_len, str_data);
10398
} else {
104-
if (is_bytes) {
105-
print(env, "b");
106-
}
107-
uni_print_quoted(print, env, str_data, str_len, is_bytes);
99+
uni_print_quoted(print, env, str_data, str_len);
108100
}
109101
}
110102

@@ -303,7 +295,7 @@ STATIC MP_DEFINE_CONST_DICT(str_locals_dict, str_locals_dict_table);
303295
const mp_obj_type_t mp_type_str = {
304296
{ &mp_type_type },
305297
.name = MP_QSTR_str,
306-
.print = str_print,
298+
.print = uni_print,
307299
.make_new = str_make_new,
308300
.binary_op = str_binary_op,
309301
.subscr = str_subscr,

0 commit comments

Comments
 (0)