File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -310,9 +310,10 @@ def check_table_size(size, table_size):
310310 self .assertEqual (writer .get_table_size (), table_size )
311311
312312 check_table_size (0 , PySet_MINSIZE )
313- check_table_size (PySet_MINSIZE - 1 , PySet_MINSIZE )
314- check_table_size (PySet_MINSIZE , PySet_MINSIZE * 2 )
315- check_table_size (2 ** 15 - 1 , 2 ** 15 )
313+ check_table_size (PySet_MINSIZE // 2 , PySet_MINSIZE )
314+ check_table_size (PySet_MINSIZE - 1 , PySet_MINSIZE * 2 )
315+ check_table_size (PySet_MINSIZE , PySet_MINSIZE * 4 )
316+ check_table_size (2 ** 15 - 1 , 2 ** 16 )
316317
317318 def create_items (self , nitem ):
318319 # Use mortal (and unique) objects to be able to detect reference leaks
Original file line number Diff line number Diff line change @@ -3251,13 +3251,14 @@ PyFrozenSetWriter_Create(Py_ssize_t size)
32513251 return NULL ;
32523252 }
32533253
3254- PyObject * frozenset = make_new_set_untracked (& PyFrozenSet_Type , NULL );
3255- if (frozenset == NULL ) {
3254+ PyObject * frozenset_obj = make_new_set_untracked (& PyFrozenSet_Type , NULL );
3255+ if (frozenset_obj == NULL ) {
32563256 return NULL ;
32573257 }
3258+ PySetObject * frozenset = _PySet_CAST (frozenset_obj );
32583259
3259- if (size > 0 ) {
3260- if (set_table_resize (_PySet_CAST ( frozenset ) , size ) != 0 ) {
3260+ if (size > 0 && size * 5 >= frozenset -> mask * 3 ) {
3261+ if (set_table_resize (frozenset , size * 2 ) != 0 ) {
32613262 Py_DECREF (frozenset );
32623263 return NULL ;
32633264 }
You can’t perform that action at this time.
0 commit comments