py: Inline single use of mp_obj_str_get_len in mp_obj_len_maybe.
Gets rid of redundant double check for string type. Also remove obsolete declaration of mp_obj_str_get_hash.
This commit is contained in:
parent
8bf00084b6
commit
516982242d
4
py/obj.c
4
py/obj.c
|
@ -33,6 +33,7 @@
|
||||||
#include "py/obj.h"
|
#include "py/obj.h"
|
||||||
#include "py/objtype.h"
|
#include "py/objtype.h"
|
||||||
#include "py/objint.h"
|
#include "py/objint.h"
|
||||||
|
#include "py/objstr.h"
|
||||||
#include "py/runtime0.h"
|
#include "py/runtime0.h"
|
||||||
#include "py/runtime.h"
|
#include "py/runtime.h"
|
||||||
#include "py/stackctrl.h"
|
#include "py/stackctrl.h"
|
||||||
|
@ -422,7 +423,8 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
|
||||||
MP_OBJ_IS_STR(o_in) ||
|
MP_OBJ_IS_STR(o_in) ||
|
||||||
#endif
|
#endif
|
||||||
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
|
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
|
||||||
return MP_OBJ_NEW_SMALL_INT(mp_obj_str_get_len(o_in));
|
GET_STR_LEN(o_in, l);
|
||||||
|
return MP_OBJ_NEW_SMALL_INT(l);
|
||||||
} else {
|
} else {
|
||||||
mp_obj_type_t *type = mp_obj_get_type(o_in);
|
mp_obj_type_t *type = mp_obj_get_type(o_in);
|
||||||
if (type->unary_op != NULL) {
|
if (type->unary_op != NULL) {
|
||||||
|
|
2
py/obj.h
2
py/obj.h
|
@ -560,8 +560,6 @@ void mp_init_emergency_exception_buf(void);
|
||||||
|
|
||||||
// str
|
// str
|
||||||
bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
|
bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
|
||||||
mp_uint_t mp_obj_str_get_hash(mp_obj_t self_in);
|
|
||||||
mp_uint_t mp_obj_str_get_len(mp_obj_t self_in);
|
|
||||||
qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr
|
qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr
|
||||||
const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
|
const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
|
||||||
const char *mp_obj_str_get_data(mp_obj_t self_in, mp_uint_t *len);
|
const char *mp_obj_str_get_data(mp_obj_t self_in, mp_uint_t *len);
|
||||||
|
|
10
py/objstr.c
10
py/objstr.c
|
@ -1996,16 +1996,6 @@ STATIC void bad_implicit_conversion(mp_obj_t self_in) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mp_uint_t mp_obj_str_get_len(mp_obj_t self_in) {
|
|
||||||
// TODO This has a double check for the type, one in obj.c and one here
|
|
||||||
if (MP_OBJ_IS_STR_OR_BYTES(self_in)) {
|
|
||||||
GET_STR_LEN(self_in, l);
|
|
||||||
return l;
|
|
||||||
} else {
|
|
||||||
bad_implicit_conversion(self_in);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// use this if you will anyway convert the string to a qstr
|
// use this if you will anyway convert the string to a qstr
|
||||||
// will be more efficient for the case where it's already a qstr
|
// will be more efficient for the case where it's already a qstr
|
||||||
qstr mp_obj_str_get_qstr(mp_obj_t self_in) {
|
qstr mp_obj_str_get_qstr(mp_obj_t self_in) {
|
||||||
|
|
Loading…
Reference in New Issue