Skip to content

Commit d60cace

Browse files
committed
Use qstrs to save an additional 4 bytes
1 parent 92917b8 commit d60cace

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

py/obj.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,12 @@ mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
5757
}
5858
}
5959

60+
qstr mp_obj_get_type_qstr(mp_const_obj_t o_in) {
61+
return mp_obj_get_type(o_in)->name;
62+
}
63+
6064
const char *mp_obj_get_type_str(mp_const_obj_t o_in) {
61-
return qstr_str(mp_obj_get_type(o_in)->name);
65+
return qstr_str(mp_obj_get_type_qstr(o_in));
6266
}
6367

6468
void mp_obj_print_helper(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t kind) {
@@ -263,7 +267,7 @@ mp_int_t mp_obj_get_int(mp_const_obj_t arg) {
263267
mp_raise_TypeError(translate("can't convert to int"));
264268
} else {
265269
mp_raise_TypeError_varg(
266-
translate("can't convert %s to %s"), mp_obj_get_type_str(arg), "int");
270+
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_int);
267271
}
268272
}
269273
}
@@ -326,7 +330,7 @@ mp_float_t mp_obj_get_float(mp_obj_t arg) {
326330
mp_raise_TypeError(translate("can't convert to float"));
327331
} else {
328332
mp_raise_TypeError_varg(
329-
translate("can't convert %s to %s"), mp_obj_get_type_str(arg), "float");
333+
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_float);
330334
}
331335
}
332336

@@ -359,7 +363,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
359363
mp_raise_TypeError(translate("can't convert to complex"));
360364
} else {
361365
mp_raise_TypeError_varg(
362-
translate("can't convert %s to %s"), mp_obj_get_type_str(arg), "complex");
366+
translate("can't convert %q to %q"), mp_obj_get_type_qstr(arg), MP_QSTR_complex);
363367
}
364368
}
365369
}

py/obj.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,7 @@ mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);
680680

681681
mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in);
682682
const char *mp_obj_get_type_str(mp_const_obj_t o_in);
683+
qstr mp_obj_get_type_qstr(mp_const_obj_t o_in);
683684
bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo); // arguments should be type objects
684685
mp_obj_t mp_instance_cast_to_native_base(mp_obj_t self_in, mp_const_obj_t native_type);
685686

py/objint.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,9 +141,9 @@ STATIC mp_fp_as_int_class_t mp_classify_fp_as_int(mp_float_t val) {
141141
mp_obj_t mp_obj_new_int_from_float(mp_float_t val) {
142142
int cl = fpclassify(val);
143143
if (cl == FP_INFINITE) {
144-
mp_raise_OverflowError_varg(translate("can't convert %s to %s"), "inf", "int");
144+
mp_raise_OverflowError_varg(translate("can't convert %q to %q"), MP_QSTR_inf, MP_QSTR_int);
145145
} else if (cl == FP_NAN) {
146-
mp_raise_ValueError_varg(translate("can't convert %s to %s"), "NaN", "int");
146+
mp_raise_ValueError_varg(translate("can't convert %q to %q"), MP_QSTR_NaN, "int");
147147
} else {
148148
mp_fp_as_int_class_t icl = mp_classify_fp_as_int(val);
149149
if (icl == MP_FP_CLASS_FIT_SMALLINT) {

shared-bindings/i2cperipheral/I2CPeripheral.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ STATIC mp_obj_t i2cperipheral_i2c_peripheral_make_new(const mp_obj_type_t *type,
8686
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
8787
mp_int_t value;
8888
if (!mp_obj_get_int_maybe(item, &value)) {
89-
mp_raise_TypeError_varg(translate("can't convert %s to %s"), "address", "int");
89+
mp_raise_TypeError_varg(translate("can't convert %q to %q"), MP_QSTR_address, MP_QSTR_int);
9090
}
9191
if (value < 0x00 || value > 0x7f) {
9292
mp_raise_ValueError(translate("address out of bounds"));

0 commit comments

Comments
 (0)