aboutsummaryrefslogtreecommitdiff
path: root/ports/unix
diff options
context:
space:
mode:
authorDamien George2017-11-16 13:17:51 +1100
committerDamien George2017-11-16 13:17:51 +1100
commit4601759bf59e16b860a3f082e9aa4ea78356bf92 (patch)
tree138bedf76b8b9155835bbaf935f2c108d8ff3ec0 /ports/unix
parent6bc55b657b900dd92ebb8b4a8c393644a30dd7e6 (diff)
py/objstr: Remove "make_qstr_if_not_already" arg from mp_obj_new_str.
This patch simplifies the str creation API to favour the common case of creating a str object that is not forced to be interned. To force interning of a new str the new mp_obj_new_str_via_qstr function is added, and should only be used if warranted. Apart from simplifying the mp_obj_new_str function (and making it have the same signature as mp_obj_new_bytes), this patch also reduces code size by a bit (-16 bytes for bare-arm and roughly -40 bytes on the bare-metal archs).
Diffstat (limited to 'ports/unix')
-rw-r--r--ports/unix/coverage.c6
-rw-r--r--ports/unix/main.c6
-rw-r--r--ports/unix/modffi.c2
-rw-r--r--ports/unix/modjni.c2
-rw-r--r--ports/unix/modos.c4
5 files changed, 10 insertions, 10 deletions
diff --git a/ports/unix/coverage.c b/ports/unix/coverage.c
index 651db0a94..e2896c2dd 100644
--- a/ports/unix/coverage.c
+++ b/ports/unix/coverage.c
@@ -227,7 +227,7 @@ STATIC mp_obj_t extra_coverage(void) {
mp_printf(&mp_plat_print, "# str\n");
// intern string
- mp_printf(&mp_plat_print, "%d\n", MP_OBJ_IS_QSTR(mp_obj_str_intern(mp_obj_new_str("intern me", 9, false))));
+ mp_printf(&mp_plat_print, "%d\n", MP_OBJ_IS_QSTR(mp_obj_str_intern(mp_obj_new_str("intern me", 9))));
}
// mpz
@@ -260,12 +260,12 @@ STATIC mp_obj_t extra_coverage(void) {
// call mp_call_function_1_protected
mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), MP_OBJ_NEW_SMALL_INT(1));
// call mp_call_function_1_protected with invalid args
- mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), mp_obj_new_str("abc", 3, false));
+ mp_call_function_1_protected(MP_OBJ_FROM_PTR(&mp_builtin_abs_obj), mp_obj_new_str("abc", 3));
// call mp_call_function_2_protected
mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), MP_OBJ_NEW_SMALL_INT(1), MP_OBJ_NEW_SMALL_INT(1));
// call mp_call_function_2_protected with invalid args
- mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str("abc", 3, false), mp_obj_new_str("abc", 3, false));
+ mp_call_function_2_protected(MP_OBJ_FROM_PTR(&mp_builtin_divmod_obj), mp_obj_new_str("abc", 3), mp_obj_new_str("abc", 3));
}
// warning
diff --git a/ports/unix/main.c b/ports/unix/main.c
index e1cd33fc1..25f3e04fb 100644
--- a/ports/unix/main.c
+++ b/ports/unix/main.c
@@ -481,7 +481,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
vstr_add_strn(&vstr, p + 1, p1 - p - 1);
path_items[i] = mp_obj_new_str_from_vstr(&mp_type_str, &vstr);
} else {
- path_items[i] = MP_OBJ_NEW_QSTR(qstr_from_strn(p, p1 - p));
+ path_items[i] = mp_obj_new_str_via_qstr(p, p1 - p);
}
p = p1 + 1;
}
@@ -537,7 +537,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
return usage(argv);
}
mp_obj_t import_args[4];
- import_args[0] = mp_obj_new_str(argv[a + 1], strlen(argv[a + 1]), false);
+ import_args[0] = mp_obj_new_str(argv[a + 1], strlen(argv[a + 1]));
import_args[1] = import_args[2] = mp_const_none;
// Ask __import__ to handle imported module specially - set its __name__
// to __main__, and also return this leaf module, not top-level package
@@ -603,7 +603,7 @@ MP_NOINLINE int main_(int argc, char **argv) {
// Set base dir of the script as first entry in sys.path
char *p = strrchr(basedir, '/');
- path_items[0] = MP_OBJ_NEW_QSTR(qstr_from_strn(basedir, p - basedir));
+ path_items[0] = mp_obj_new_str_via_qstr(basedir, p - basedir);
free(pathbuf);
set_sys_argv(argv, argc, a);
diff --git a/ports/unix/modffi.c b/ports/unix/modffi.c
index 78adccac1..024f83c14 100644
--- a/ports/unix/modffi.c
+++ b/ports/unix/modffi.c
@@ -144,7 +144,7 @@ STATIC mp_obj_t return_ffi_value(ffi_arg val, char type)
if (!s) {
return mp_const_none;
}
- return mp_obj_new_str(s, strlen(s), false);
+ return mp_obj_new_str(s, strlen(s));
}
case 'v':
return mp_const_none;
diff --git a/ports/unix/modjni.c b/ports/unix/modjni.c
index f29c095cf..8ec5ae54d 100644
--- a/ports/unix/modjni.c
+++ b/ports/unix/modjni.c
@@ -337,7 +337,7 @@ STATIC mp_obj_t new_jobject(jobject jo) {
return mp_const_none;
} else if (JJ(IsInstanceOf, jo, String_class)) {
const char *s = JJ(GetStringUTFChars, jo, NULL);
- mp_obj_t ret = mp_obj_new_str(s, strlen(s), false);
+ mp_obj_t ret = mp_obj_new_str(s, strlen(s));
JJ(ReleaseStringUTFChars, jo, s);
return ret;
} else if (JJ(IsInstanceOf, jo, Class_class)) {
diff --git a/ports/unix/modos.c b/ports/unix/modos.c
index 327116a0a..808d12adb 100644
--- a/ports/unix/modos.c
+++ b/ports/unix/modos.c
@@ -133,7 +133,7 @@ STATIC mp_obj_t mod_os_getenv(mp_obj_t var_in) {
if (s == NULL) {
return mp_const_none;
}
- return mp_obj_new_str(s, strlen(s), false);
+ return mp_obj_new_str(s, strlen(s));
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_os_getenv_obj, mod_os_getenv);
@@ -171,7 +171,7 @@ STATIC mp_obj_t listdir_next(mp_obj_t self_in) {
}
mp_obj_tuple_t *t = MP_OBJ_TO_PTR(mp_obj_new_tuple(3, NULL));
- t->items[0] = mp_obj_new_str(dirent->d_name, strlen(dirent->d_name), false);
+ t->items[0] = mp_obj_new_str(dirent->d_name, strlen(dirent->d_name));
#ifdef _DIRENT_HAVE_D_TYPE
t->items[1] = MP_OBJ_NEW_SMALL_INT(dirent->d_type);
#else