Skip to content

Commit 5169822

Browse files
committed
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.
1 parent 8bf0008 commit 5169822

File tree

3 files changed

+3
-13
lines changed

3 files changed

+3
-13
lines changed

py/obj.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "py/obj.h"
3434
#include "py/objtype.h"
3535
#include "py/objint.h"
36+
#include "py/objstr.h"
3637
#include "py/runtime0.h"
3738
#include "py/runtime.h"
3839
#include "py/stackctrl.h"
@@ -422,7 +423,8 @@ mp_obj_t mp_obj_len_maybe(mp_obj_t o_in) {
422423
MP_OBJ_IS_STR(o_in) ||
423424
#endif
424425
MP_OBJ_IS_TYPE(o_in, &mp_type_bytes)) {
425-
return MP_OBJ_NEW_SMALL_INT(mp_obj_str_get_len(o_in));
426+
GET_STR_LEN(o_in, l);
427+
return MP_OBJ_NEW_SMALL_INT(l);
426428
} else {
427429
mp_obj_type_t *type = mp_obj_get_type(o_in);
428430
if (type->unary_op != NULL) {

py/obj.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,6 @@ void mp_init_emergency_exception_buf(void);
560560

561561
// str
562562
bool mp_obj_str_equal(mp_obj_t s1, mp_obj_t s2);
563-
mp_uint_t mp_obj_str_get_hash(mp_obj_t self_in);
564-
mp_uint_t mp_obj_str_get_len(mp_obj_t self_in);
565563
qstr mp_obj_str_get_qstr(mp_obj_t self_in); // use this if you will anyway convert the string to a qstr
566564
const char *mp_obj_str_get_str(mp_obj_t self_in); // use this only if you need the string to be null terminated
567565
const char *mp_obj_str_get_data(mp_obj_t self_in, mp_uint_t *len);

py/objstr.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1996,16 +1996,6 @@ STATIC void bad_implicit_conversion(mp_obj_t self_in) {
19961996
}
19971997
}
19981998

1999-
mp_uint_t mp_obj_str_get_len(mp_obj_t self_in) {
2000-
// TODO This has a double check for the type, one in obj.c and one here
2001-
if (MP_OBJ_IS_STR_OR_BYTES(self_in)) {
2002-
GET_STR_LEN(self_in, l);
2003-
return l;
2004-
} else {
2005-
bad_implicit_conversion(self_in);
2006-
}
2007-
}
2008-
20091999
// use this if you will anyway convert the string to a qstr
20102000
// will be more efficient for the case where it's already a qstr
20112001
qstr mp_obj_str_get_qstr(mp_obj_t self_in) {

0 commit comments

Comments
 (0)