summaryrefslogtreecommitdiff
path: root/py/qstr.c
diff options
context:
space:
mode:
Diffstat (limited to 'py/qstr.c')
-rwxr-xr-xpy/qstr.c35
1 files changed, 5 insertions, 30 deletions
diff --git a/py/qstr.c b/py/qstr.c
index de4dc6240..c68f3dfec 100755
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -128,14 +128,12 @@ void qstr_init(void) {
STATIC const byte *find_qstr(qstr q) {
// search pool for this qstr
- for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) {
- if (q >= pool->total_prev_len) {
- return pool->qstrs[q - pool->total_prev_len];
- }
+ // total_prev_len==0 in the final pool, so the loop will always terminate
+ qstr_pool_t *pool = MP_STATE_VM(last_pool);
+ while (q < pool->total_prev_len) {
+ pool = pool->prev;
}
-
- // not found
- return 0;
+ return pool->qstrs[q - pool->total_prev_len];
}
// qstr_mutex must be taken while in this function
@@ -248,29 +246,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(gc_make_long_lived(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));
}