qstr: Use const consistently to avoid a cast.

This commit is contained in:
Artyom Skrobov 2021-05-04 03:35:45 -04:00
parent f5f18b2cef
commit 2d73ba2186
3 changed files with 7 additions and 7 deletions

View File

@ -123,7 +123,7 @@ void qstr_init(void) {
STATIC const char *find_qstr(qstr q, qstr_attr_t *attr) {
// 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;
}
@ -181,7 +181,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) {
qstr_attr_t *attrs = pool->attrs;
for (mp_uint_t at = 0, top = pool->len; at < top; at++) {
if (attrs[at].hash == str_hash && attrs[at].len == str_len && memcmp(pool->qstrs[at], str, str_len) == 0) {
@ -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 (const qstr_attr_t *q = pool->attrs, *q_top = pool->attrs + pool->len; q < q_top; q++) {
@ -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);
}
}

View File

@ -65,7 +65,7 @@ typedef struct _qstr_attr_t {
} qstr_attr_t;
typedef struct _qstr_pool_t {
struct _qstr_pool_t *prev;
const struct _qstr_pool_t *prev;
size_t total_prev_len;
size_t alloc;
size_t len;

View File

@ -878,7 +878,7 @@ def freeze_mpy(base_qstrs, raw_codes):
print()
print("extern const qstr_pool_t mp_qstr_const_pool;")
print("const qstr_pool_t mp_qstr_frozen_const_pool = {")
print(" (qstr_pool_t*)&mp_qstr_const_pool, // previous pool")
print(" &mp_qstr_const_pool, // previous pool")
print(" MP_QSTRnumber_of, // previous pool size")
print(" %u, // allocated entries" % qstr_pool_alloc)
print(" %u, // used entries" % len(new))