summaryrefslogtreecommitdiffstatshomepage
path: root/py
diff options
context:
space:
mode:
Diffstat (limited to 'py')
-rw-r--r--py/builtin.c4
-rw-r--r--py/obj.h2
-rw-r--r--py/objarray.c4
-rw-r--r--py/objdict.c24
-rw-r--r--py/objgenerator.c8
-rw-r--r--py/objlist.c24
-rw-r--r--py/objset.c36
-rw-r--r--py/objstr.c24
-rw-r--r--py/objtuple.c6
-rw-r--r--py/objtype.c4
-rw-r--r--py/qstrdefs.h43
-rw-r--r--py/runtime.c4
12 files changed, 113 insertions, 70 deletions
diff --git a/py/builtin.c b/py/builtin.c
index 281c57dd43..1e022becbd 100644
--- a/py/builtin.c
+++ b/py/builtin.c
@@ -178,8 +178,8 @@ STATIC mp_obj_t mp_builtin_dir(uint n_args, const mp_obj_t *args) {
}
}
if (meth != NULL) {
- for (; meth->name != NULL; meth++) {
- mp_obj_list_append(dir, MP_OBJ_NEW_QSTR(qstr_from_str(meth->name)));
+ for (; meth->name != MP_QSTR_NULL; meth++) {
+ mp_obj_list_append(dir, MP_OBJ_NEW_QSTR(meth->name));
}
}
return dir;
diff --git a/py/obj.h b/py/obj.h
index 7c3ef8c55b..1c22e956b8 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -96,7 +96,7 @@ typedef bool (*mp_store_attr_fun_t)(mp_obj_t self_in, qstr attr, mp_obj_t value)
typedef bool (*mp_store_item_fun_t)(mp_obj_t self_in, mp_obj_t index, mp_obj_t value); // return true if store succeeded
typedef struct _mp_method_t {
- const char *name;
+ qstr name;
mp_const_obj_t fun;
} mp_method_t;
diff --git a/py/objarray.c b/py/objarray.c
index d77a101075..9d795c1bff 100644
--- a/py/objarray.c
+++ b/py/objarray.c
@@ -150,8 +150,8 @@ STATIC machine_int_t array_get_buffer(mp_obj_t o_in, buffer_info_t *bufinfo, int
}
STATIC const mp_method_t array_type_methods[] = {
- { "append", &array_append_obj },
- { NULL, NULL },
+ { MP_QSTR_append, &array_append_obj },
+ { MP_QSTR_NULL, NULL }, // end-of-list sentinel
};
const mp_obj_type_t mp_type_array = {
diff --git a/py/objdict.c b/py/objdict.c
index ead2d7442f..14d120a779 100644
--- a/py/objdict.c
+++ b/py/objdict.c
@@ -424,18 +424,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(dict_values_obj, dict_values);
/* dict constructors & public C API */
STATIC const mp_method_t dict_type_methods[] = {
- { "clear", &dict_clear_obj },
- { "copy", &dict_copy_obj },
- { "fromkeys", &dict_fromkeys_obj },
- { "get", &dict_get_obj },
- { "items", &dict_items_obj },
- { "keys", &dict_keys_obj },
- { "pop", &dict_pop_obj },
- { "popitem", &dict_popitem_obj },
- { "setdefault", &dict_setdefault_obj },
- { "update", &dict_update_obj },
- { "values", &dict_values_obj },
- { NULL, NULL }, // end-of-list sentinel
+ { MP_QSTR_clear, &dict_clear_obj },
+ { MP_QSTR_copy, &dict_copy_obj },
+ { MP_QSTR_fromkeys, &dict_fromkeys_obj },
+ { MP_QSTR_get, &dict_get_obj },
+ { MP_QSTR_items, &dict_items_obj },
+ { MP_QSTR_keys, &dict_keys_obj },
+ { MP_QSTR_pop, &dict_pop_obj },
+ { MP_QSTR_popitem, &dict_popitem_obj },
+ { MP_QSTR_setdefault, &dict_setdefault_obj },
+ { MP_QSTR_update, &dict_update_obj },
+ { MP_QSTR_values, &dict_values_obj },
+ { MP_QSTR_NULL, NULL }, // end-of-list sentinel
};
const mp_obj_type_t dict_type = {
diff --git a/py/objgenerator.c b/py/objgenerator.c
index 7b4c320f75..f440923ee6 100644
--- a/py/objgenerator.c
+++ b/py/objgenerator.c
@@ -193,10 +193,10 @@ STATIC mp_obj_t gen_instance_close(mp_obj_t self_in) {
STATIC MP_DEFINE_CONST_FUN_OBJ_1(gen_instance_close_obj, gen_instance_close);
STATIC const mp_method_t gen_type_methods[] = {
- { "close", &gen_instance_close_obj },
- { "send", &gen_instance_send_obj },
- { "throw", &gen_instance_throw_obj },
- { NULL, NULL }, // end-of-list sentinel
+ { MP_QSTR_close, &gen_instance_close_obj },
+ { MP_QSTR_send, &gen_instance_send_obj },
+ { MP_QSTR_throw, &gen_instance_throw_obj },
+ { MP_QSTR_NULL, NULL }, // end-of-list sentinel
};
const mp_obj_type_t gen_instance_type = {
diff --git a/py/objlist.c b/py/objlist.c
index 3083e23bb1..afc4f3cf85 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -329,18 +329,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(list_reverse_obj, list_reverse);
STATIC MP_DEFINE_CONST_FUN_OBJ_KW(list_sort_obj, 0, mp_obj_list_sort);
STATIC const mp_method_t list_type_methods[] = {
- { "append", &list_append_obj },
- { "clear", &list_clear_obj },
- { "copy", &list_copy_obj },
- { "count", &list_count_obj },
- { "extend", &list_extend_obj },
- { "index", &list_index_obj },
- { "insert", &list_insert_obj },
- { "pop", &list_pop_obj },
- { "remove", &list_remove_obj },
- { "reverse", &list_reverse_obj },
- { "sort", &list_sort_obj },
- { NULL, NULL }, // end-of-list sentinel
+ { MP_QSTR_append, &list_append_obj },
+ { MP_QSTR_clear, &list_clear_obj },
+ { MP_QSTR_copy, &list_copy_obj },
+ { MP_QSTR_count, &list_count_obj },
+ { MP_QSTR_extend, &list_extend_obj },
+ { MP_QSTR_index, &list_index_obj },
+ { MP_QSTR_insert, &list_insert_obj },
+ { MP_QSTR_pop, &list_pop_obj },
+ { MP_QSTR_remove, &list_remove_obj },
+ { MP_QSTR_reverse, &list_reverse_obj },
+ { MP_QSTR_sort, &list_sort_obj },
+ { MP_QSTR_NULL, NULL }, // end-of-list sentinel
};
const mp_obj_type_t list_type = {
diff --git a/py/objset.c b/py/objset.c
index 4f0776f893..250d132472 100644
--- a/py/objset.c
+++ b/py/objset.c
@@ -424,24 +424,24 @@ STATIC mp_obj_t set_binary_op(int op, mp_obj_t lhs, mp_obj_t rhs) {
STATIC const mp_method_t set_type_methods[] = {
- { "add", &set_add_obj },
- { "clear", &set_clear_obj },
- { "copy", &set_copy_obj },
- { "discard", &set_discard_obj },
- { "difference", &set_diff_obj },
- { "difference_update", &set_diff_update_obj },
- { "intersection", &set_intersect_obj },
- { "intersection_update", &set_intersect_update_obj },
- { "isdisjoint", &set_isdisjoint_obj },
- { "issubset", &set_issubset_obj },
- { "issuperset", &set_issuperset_obj },
- { "pop", &set_pop_obj },
- { "remove", &set_remove_obj },
- { "symmetric_difference", &set_symmetric_difference_obj },
- { "symmetric_difference_update", &set_symmetric_difference_update_obj },
- { "union", &set_union_obj },
- { "update", &set_update_obj },
- { NULL, NULL }, // end-of-list sentinel
+ { MP_QSTR_add, &set_add_obj },
+ { MP_QSTR_clear, &set_clear_obj },
+ { MP_QSTR_copy, &set_copy_obj },
+ { MP_QSTR_discard, &set_discard_obj },
+ { MP_QSTR_difference, &set_diff_obj },
+ { MP_QSTR_difference_update, &set_diff_update_obj },
+ { MP_QSTR_intersection, &set_intersect_obj },
+ { MP_QSTR_intersection_update, &set_intersect_update_obj },
+ { MP_QSTR_isdisjoint, &set_isdisjoint_obj },
+ { MP_QSTR_issubset, &set_issubset_obj },
+ { MP_QSTR_issuperset, &set_issuperset_obj },
+ { MP_QSTR_pop, &set_pop_obj },
+ { MP_QSTR_remove, &set_remove_obj },
+ { MP_QSTR_symmetric_difference, &set_symmetric_difference_obj },
+ { MP_QSTR_symmetric_difference_update, &set_symmetric_difference_update_obj },
+ { MP_QSTR_union, &set_union_obj },
+ { MP_QSTR_update, &set_update_obj },
+ { MP_QSTR_NULL, NULL }, // end-of-list sentinel
};
const mp_obj_type_t set_type = {
diff --git a/py/objstr.c b/py/objstr.c
index 3ace7b051a..d8b391d446 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -694,18 +694,18 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_2(str_partition_obj, str_partition);
STATIC MP_DEFINE_CONST_FUN_OBJ_2(str_rpartition_obj, str_rpartition);
STATIC const mp_method_t str_type_methods[] = {
- { "find", &str_find_obj },
- { "rfind", &str_rfind_obj },
- { "join", &str_join_obj },
- { "split", &str_split_obj },
- { "startswith", &str_startswith_obj },
- { "strip", &str_strip_obj },
- { "format", &str_format_obj },
- { "replace", &str_replace_obj },
- { "count", &str_count_obj },
- { "partition", &str_partition_obj },
- { "rpartition", &str_rpartition_obj },
- { NULL, NULL }, // end-of-list sentinel
+ { MP_QSTR_find, &str_find_obj },
+ { MP_QSTR_rfind, &str_rfind_obj },
+ { MP_QSTR_join, &str_join_obj },
+ { MP_QSTR_split, &str_split_obj },
+ { MP_QSTR_startswith, &str_startswith_obj },
+ { MP_QSTR_strip, &str_strip_obj },
+ { MP_QSTR_format, &str_format_obj },
+ { MP_QSTR_replace, &str_replace_obj },
+ { MP_QSTR_count, &str_count_obj },
+ { MP_QSTR_partition, &str_partition_obj },
+ { MP_QSTR_rpartition, &str_rpartition_obj },
+ { MP_QSTR_NULL, NULL }, // end-of-list sentinel
};
const mp_obj_type_t str_type = {
diff --git a/py/objtuple.c b/py/objtuple.c
index 68f5abefdf..334cf0562e 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -166,9 +166,9 @@ STATIC mp_obj_t tuple_index(uint n_args, const mp_obj_t *args) {
STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(tuple_index_obj, 2, 4, tuple_index);
STATIC const mp_method_t tuple_type_methods[] = {
- { "count", &tuple_count_obj },
- { "index", &tuple_index_obj },
- { NULL, NULL }, // end-of-list sentinel
+ { MP_QSTR_count, &tuple_count_obj },
+ { MP_QSTR_index, &tuple_index_obj },
+ { MP_QSTR_NULL, NULL }, // end-of-list sentinel
};
const mp_obj_type_t tuple_type = {
diff --git a/py/objtype.c b/py/objtype.c
index 9cb29744c7..ceec78ea37 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -41,8 +41,8 @@ STATIC mp_obj_t mp_obj_class_lookup(const mp_obj_type_t *type, qstr attr) {
} else if (type->methods != NULL) {
// search methods (the const set of methods)
- for (const mp_method_t *meth = type->methods; meth->name != NULL; meth++) {
- if (strcmp(meth->name, qstr_str(attr)) == 0) {
+ for (const mp_method_t *meth = type->methods; meth->name != MP_QSTR_NULL; meth++) {
+ if (meth->name == attr) {
return (mp_obj_t)meth->fun;
}
}
diff --git a/py/qstrdefs.h b/py/qstrdefs.h
index 1c8afe797d..a2cdf84251 100644
--- a/py/qstrdefs.h
+++ b/py/qstrdefs.h
@@ -123,7 +123,26 @@ Q(type)
Q(value)
Q(zip)
+Q(clear)
+Q(copy)
+Q(fromkeys)
+Q(get)
+Q(items)
+Q(keys)
+Q(pop)
+Q(popitem)
+Q(setdefault)
+Q(update)
+Q(values)
Q(append)
+Q(close)
+Q(send)
+Q(throw)
+Q(count)
+Q(extend)
+Q(index)
+Q(remove)
+Q(insert)
Q(pop)
Q(sort)
Q(join)
@@ -131,6 +150,30 @@ Q(strip)
Q(format)
Q(key)
Q(reverse)
+Q(add)
+Q(clear)
+Q(copy)
+Q(discard)
+Q(difference)
+Q(difference_update)
+Q(intersection)
+Q(intersection_update)
+Q(isdisjoint)
+Q(issubset)
+Q(issuperset)
+Q(pop)
+Q(remove)
+Q(symmetric_difference)
+Q(symmetric_difference_update)
+Q(union)
+Q(update)
+Q(find)
+Q(rfind)
+Q(split)
+Q(startswith)
+Q(replace)
+Q(partition)
+Q(rpartition)
Q(bound_method)
Q(closure)
diff --git a/py/runtime.c b/py/runtime.c
index cc5398552e..247a78fe1a 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -847,8 +847,8 @@ STATIC void rt_load_method_maybe(mp_obj_t base, qstr attr, mp_obj_t *dest) {
// this is a lookup in the object (ie not class or type)
const mp_method_t *meth = type->methods;
if (meth != NULL) {
- for (; meth->name != NULL; meth++) {
- if (strcmp(meth->name, qstr_str(attr)) == 0) {
+ for (; meth->name != MP_QSTR_NULL; meth++) {
+ if (meth->name == attr) {
// check if the methods are functions, static or class methods
// see http://docs.python.org/3.3/howto/descriptor.html
if (MP_OBJ_IS_TYPE(meth->fun, &mp_type_staticmethod)) {