summaryrefslogtreecommitdiff
path: root/py/qstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-11-01 13:16:16 +1100
committerDamien George <damien.p.george@gmail.com>2017-11-01 13:16:16 +1100
commit487dbdb26748b86cf247600af187437310311145 (patch)
tree4b01d33357ced617a5e4af54845174d9e16ef42b /py/qstr.c
parentfe45d78b1edd6d2202c3544797885cb0b12d4f03 (diff)
py/compile: Use alloca instead of qstr_build when compiling import name.
The technique of using alloca is how dotted import names are composed in mp_import_from and mp_builtin___import__, so use the same technique in the compiler. This puts less pressure on the heap (only the stack is used if the qstr already exists, and if it doesn't exist then the standard qstr block memory is used for the new qstr rather than a separate chunk of the heap) and reduces overall code size.
Diffstat (limited to 'py/qstr.c')
-rw-r--r--py/qstr.c23
1 files changed, 0 insertions, 23 deletions
diff --git a/py/qstr.c b/py/qstr.c
index 95c9b6835..a3c9612c6 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -243,29 +243,6 @@ qstr qstr_from_strn(const char *str, size_t len) {
return q;
}
-byte *qstr_build_start(size_t len, byte **q_ptr) {
- assert(len < (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN)));
- *q_ptr = m_new(byte, MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len + 1);
- Q_SET_LENGTH(*q_ptr, len);
- return Q_GET_DATA(*q_ptr);
-}
-
-qstr qstr_build_end(byte *q_ptr) {
- QSTR_ENTER();
- qstr q = qstr_find_strn((const char*)Q_GET_DATA(q_ptr), Q_GET_LENGTH(q_ptr));
- if (q == 0) {
- size_t len = Q_GET_LENGTH(q_ptr);
- mp_uint_t hash = qstr_compute_hash(Q_GET_DATA(q_ptr), len);
- Q_SET_HASH(q_ptr, hash);
- q_ptr[MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len] = '\0';
- q = qstr_add(q_ptr);
- } else {
- m_del(byte, q_ptr, Q_GET_ALLOC(q_ptr));
- }
- QSTR_EXIT();
- return q;
-}
-
mp_uint_t qstr_hash(qstr q) {
return Q_GET_HASH(find_qstr(q));
}