Skip to content

Commit 8e323b8

Browse files
committed
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.
1 parent 3990a52 commit 8e323b8

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

py/qstr.c

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,12 @@ void qstr_init(void) {
127127

128128
STATIC const byte *find_qstr(qstr q) {
129129
// search pool for this qstr
130-
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) {
131-
if (q >= pool->total_prev_len) {
132-
return pool->qstrs[q - pool->total_prev_len];
133-
}
130+
// total_prev_len==0 in the final pool, so the loop will always terminate
131+
qstr_pool_t *pool = MP_STATE_VM(last_pool);
132+
while (q < pool->total_prev_len) {
133+
pool = pool->prev;
134134
}
135-
136-
// not found
137-
return 0;
135+
return pool->qstrs[q - pool->total_prev_len];
138136
}
139137

140138
// qstr_mutex must be taken while in this function

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy