aboutsummaryrefslogtreecommitdiff
path: root/py/qstr.c
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2017-11-29 16:58:27 +1100
committerDamien George <damien.p.george@gmail.com>2017-11-29 17:01:39 +1100
commit8e323b8fa84277531685985327fb682761abd53d (patch)
tree07da54237b834513db77cd586f6c9a71e9abc798 /py/qstr.c
parent3990a52c0f071a7a48cc276f30785930f31eed39 (diff)
py/qstr: Rewrite find_qstr to make manifest that it returns a valid ptr.
So long as the input qstr identifier is valid (below the maximum number of qstrs) the function will always return a valid pointer. This patch eliminates the "return 0" dead-code.
Diffstat (limited to 'py/qstr.c')
-rw-r--r--py/qstr.c12
1 files changed, 5 insertions, 7 deletions
diff --git a/py/qstr.c b/py/qstr.c
index a3c9612c6..08c3e2505 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -127,14 +127,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