File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 130130#define MICROPY_ALLOC_QSTR_CHUNK_INIT (128)
131131#endif
132132
133+ // Max number of entries in newly allocated QSTR pools. Smaller numbers may make QSTR lookups
134+ // slightly slower but reduce the waste of unused spots.
135+ #ifndef MICROPY_QSTR_POOL_MAX_ENTRIES
136+ #define MICROPY_QSTR_POOL_MAX_ENTRIES (64)
137+ #endif
138+
133139// Initial amount for lexer indentation level
134140#ifndef MICROPY_ALLOC_LEXER_INDENT_INIT
135141#define MICROPY_ALLOC_LEXER_INDENT_INIT (10)
Original file line number Diff line number Diff line change @@ -144,14 +144,18 @@ STATIC qstr qstr_add(const byte *q_ptr) {
144144
145145 // make sure we have room in the pool for a new qstr
146146 if (MP_STATE_VM (last_pool )-> len >= MP_STATE_VM (last_pool )-> alloc ) {
147- qstr_pool_t * pool = m_new_ll_obj_var_maybe (qstr_pool_t , const char * , MP_STATE_VM (last_pool )-> alloc * 2 );
147+ uint32_t new_pool_length = MP_STATE_VM (last_pool )-> alloc * 2 ;
148+ if (new_pool_length > MICROPY_QSTR_POOL_MAX_ENTRIES ) {
149+ new_pool_length = MICROPY_QSTR_POOL_MAX_ENTRIES ;
150+ }
151+ qstr_pool_t * pool = m_new_ll_obj_var_maybe (qstr_pool_t , const char * , new_pool_length );
148152 if (pool == NULL ) {
149153 QSTR_EXIT ();
150- m_malloc_fail (MP_STATE_VM ( last_pool ) -> alloc * 2 );
154+ m_malloc_fail (new_pool_length );
151155 }
152156 pool -> prev = MP_STATE_VM (last_pool );
153157 pool -> total_prev_len = MP_STATE_VM (last_pool )-> total_prev_len + MP_STATE_VM (last_pool )-> len ;
154- pool -> alloc = MP_STATE_VM ( last_pool ) -> alloc * 2 ;
158+ pool -> alloc = new_pool_length ;
155159 pool -> len = 0 ;
156160 MP_STATE_VM (last_pool ) = pool ;
157161 DEBUG_printf ("QSTR: allocate new pool of size %d\n" , MP_STATE_VM (last_pool )-> alloc );
You can’t perform that action at this time.
0 commit comments