Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita75b02e

Browse files
committed
py: Improve efficiency of MP_OBJ_IS_STR_OR_BYTES.
Saves ROM (16 on stmhal, 240 on 64-bit unix) and should be quicker sincethere is 1 less branch.
1 parentad4c014 commita75b02e

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

‎py/obj.h‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ typedef struct _mp_obj_base_t mp_obj_base_t;
7474
#defineMP_OBJ_IS_TYPE(o,t) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type == (t))) // this does not work for checking int, str or fun; use below macros for that
7575
#defineMP_OBJ_IS_INT(o) (MP_OBJ_IS_SMALL_INT(o) || MP_OBJ_IS_TYPE(o, &mp_type_int))
7676
#defineMP_OBJ_IS_STR(o) (MP_OBJ_IS_QSTR(o) || MP_OBJ_IS_TYPE(o, &mp_type_str))
77-
#defineMP_OBJ_IS_STR_OR_BYTES(o) (MP_OBJ_IS_STR(o) ||MP_OBJ_IS_TYPE(o, &mp_type_bytes))
77+
#defineMP_OBJ_IS_STR_OR_BYTES(o) (MP_OBJ_IS_QSTR(o) ||(MP_OBJ_IS_OBJ(o) && ((mp_obj_base_t*)(o))->type->binary_op == mp_obj_str_binary_op))
7878
#defineMP_OBJ_IS_FUN(o) (MP_OBJ_IS_OBJ(o) && (((mp_obj_base_t*)(o))->type->binary_op == mp_obj_fun_binary_op))
7979

8080
#defineMP_OBJ_SMALL_INT_VALUE(o) (((mp_int_t)(o)) >> 1)

‎py/objint.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
#include"smallint.h"
3939
#include"mpz.h"
4040
#include"objint.h"
41+
#include"objstr.h"
4142
#include"runtime0.h"
4243
#include"runtime.h"
4344

‎py/objstr.c‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,9 @@ STATIC const byte *find_subbytes(const byte *haystack, mp_uint_t hlen, const byt
247247
returnNULL;
248248
}
249249

250+
// Note: this function is used to check if an object is a str or bytes, which
251+
// works because both those types use it as their binary_op method. Revisit
252+
// MP_OBJ_IS_STR_OR_BYTES if this fact changes.
250253
mp_obj_tmp_obj_str_binary_op(intop,mp_obj_tlhs_in,mp_obj_trhs_in) {
251254
GET_STR_DATA_LEN(lhs_in,lhs_data,lhs_len);
252255
mp_obj_type_t*lhs_type=mp_obj_get_type(lhs_in);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp