@@ -543,35 +543,23 @@ try_full_cache_hit(
543543 return -1 ;
544544 }
545545
546- Py_ssize_t cached_size = PyList_GET_SIZE (entry -> frame_list );
547- PyObject * parent_slice = NULL ;
548- if (cached_size > 1 ) {
549- parent_slice = PyList_GetSlice (entry -> frame_list , 1 , cached_size );
550- if (!parent_slice ) {
551- Py_XDECREF (current_frame );
552- return -1 ;
553- }
554- }
555-
556546 if (current_frame != NULL ) {
557547 if (PyList_Append (ctx -> frame_info , current_frame ) < 0 ) {
558548 Py_DECREF (current_frame );
559- Py_XDECREF (parent_slice );
560549 return -1 ;
561550 }
562551 Py_DECREF (current_frame );
563552 STATS_ADD (unwinder , frames_read_from_memory , 1 );
564553 }
565554
566- if (parent_slice ) {
567- Py_ssize_t cur_size = PyList_GET_SIZE (ctx -> frame_info );
568- int result = PyList_SetSlice (ctx -> frame_info , cur_size , cur_size , parent_slice );
569- Py_DECREF (parent_slice );
570- if (result < 0 ) {
555+ Py_ssize_t cached_size = PyList_GET_SIZE (entry -> frame_list );
556+ for (Py_ssize_t i = 1 ; i < cached_size ; i ++ ) {
557+ PyObject * cached_frame = PyList_GET_ITEM (entry -> frame_list , i );
558+ if (PyList_Append (ctx -> frame_info , cached_frame ) < 0 ) {
571559 return -1 ;
572560 }
573- STATS_ADD (unwinder , frames_read_from_cache , cached_size - 1 );
574561 }
562+ STATS_ADD (unwinder , frames_read_from_cache , cached_size > 1 ? cached_size - 1 : 0 );
575563
576564 STATS_INC (unwinder , frame_cache_hits );
577565 return 1 ;
0 commit comments