summaryrefslogtreecommitdiff
path: root/py/qstr.c
diff options
context:
space:
mode:
authorArtyom Skrobov <tyomitch@gmail.com>2021-05-04 03:35:45 -0400
committerDamien George <damien@micropython.org>2022-02-11 22:55:02 +1100
commitf46a7140f55a8f6d80f9c2d5f8db7af3de116794 (patch)
tree7938222007b43313e02c0883a6a24d1727872ecb /py/qstr.c
parent18b1ba086c0e5547ca81030bf13b026961f80720 (diff)
py/qstr: Use `const` consistently to avoid a cast.
Originally at adafruit#4707 Signed-off-by: Artyom Skrobov <tyomitch@gmail.com>
Diffstat (limited to 'py/qstr.c')
-rw-r--r--py/qstr.c20
1 files changed, 10 insertions, 10 deletions
diff --git a/py/qstr.c b/py/qstr.c
index 848a58330..f9ca10683 100644
--- a/py/qstr.c
+++ b/py/qstr.c
@@ -122,10 +122,10 @@ void qstr_init(void) {
#endif
}
-STATIC qstr_pool_t *find_qstr(qstr *q) {
+STATIC const qstr_pool_t *find_qstr(qstr *q) {
// search pool for this qstr
// total_prev_len==0 in the final pool, so the loop will always terminate
- qstr_pool_t *pool = MP_STATE_VM(last_pool);
+ const qstr_pool_t *pool = MP_STATE_VM(last_pool);
while (*q < pool->total_prev_len) {
pool = pool->prev;
}
@@ -184,7 +184,7 @@ qstr qstr_find_strn(const char *str, size_t str_len) {
mp_uint_t str_hash = qstr_compute_hash((const byte *)str, str_len);
// search pools for the data
- for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) {
+ for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) {
for (mp_uint_t at = 0, top = pool->len; at < top; at++) {
if (pool->hashes[at] == str_hash && pool->lengths[at] == str_len
&& memcmp(pool->qstrs[at], str, str_len) == 0) {
@@ -264,22 +264,22 @@ qstr qstr_from_strn(const char *str, size_t len) {
}
mp_uint_t qstr_hash(qstr q) {
- qstr_pool_t *pool = find_qstr(&q);
+ const qstr_pool_t *pool = find_qstr(&q);
return pool->hashes[q];
}
size_t qstr_len(qstr q) {
- qstr_pool_t *pool = find_qstr(&q);
+ const qstr_pool_t *pool = find_qstr(&q);
return pool->lengths[q];
}
const char *qstr_str(qstr q) {
- qstr_pool_t *pool = find_qstr(&q);
+ const qstr_pool_t *pool = find_qstr(&q);
return pool->qstrs[q];
}
const byte *qstr_data(qstr q, size_t *len) {
- qstr_pool_t *pool = find_qstr(&q);
+ const qstr_pool_t *pool = find_qstr(&q);
*len = pool->lengths[q];
return (byte *)pool->qstrs[q];
}
@@ -290,7 +290,7 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si
*n_qstr = 0;
*n_str_data_bytes = 0;
*n_total_bytes = 0;
- for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
+ for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
*n_pool += 1;
*n_qstr += pool->len;
for (qstr_len_t *l = pool->lengths, *l_top = pool->lengths + pool->len; l < l_top; l++) {
@@ -310,8 +310,8 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si
#if MICROPY_PY_MICROPYTHON_MEM_INFO
void qstr_dump_data(void) {
QSTR_ENTER();
- for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
- for (const char **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
+ for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
+ for (const char *const *q = pool->qstrs, *const *q_top = pool->qstrs + pool->len; q < q_top; q++) {
mp_printf(&mp_plat_print, "Q(%s)\n", *q);
}
}