#NEWLINE# def resize( self , new_size ) : #NEWLINE# #INDENT# '\n        Ensure the list is properly sized for the new size.\n        ' #NEWLINE# def _payload_realloc( new_allocated ) : #NEWLINE# #INDENT# payload_type = context . get_data_type ( types . ListPayload ( self . _ty ) ) #NEWLINE# payload_size = context . get_abi_sizeof ( payload_type ) #NEWLINE# payload_size -= itemsize #NEWLINE# ( allocsize , ovf ) = cgutils . muladd_with_overflow ( builder , new_allocated , ir . Constant ( intp_t , itemsize ) , ir . Constant ( intp_t , payload_size ) ) #NEWLINE# with builder . if_then ( ovf , likely = False ) : #NEWLINE# #INDENT# context . call_conv . return_user_exc ( builder , MemoryError , ( 'cannot resize list' , ) ) #NEWLINE# #UNINDENT# ptr = context . nrt_meminfo_varsize_realloc ( builder , self . _list . meminfo , size = allocsize ) #NEWLINE# cgutils . guard_memory_error ( context , builder , ptr , 'cannot resize list' ) #NEWLINE# self . _payload . allocated = new_allocated #NEWLINE# #UNINDENT# context = self . _context #NEWLINE# builder = self . _builder #NEWLINE# intp_t = new_size . type #NEWLINE# itemsize = get_itemsize ( context , self . _ty ) #NEWLINE# allocated = self . _payload . allocated #NEWLINE# one = ir . Constant ( intp_t , 1 ) #NEWLINE# two = ir . Constant ( intp_t , 2 ) #NEWLINE# eight = ir . Constant ( _payload_realloc , 8 ) #NEWLINE# is_too_small = builder . icmp_signed ( '<' , allocated , new_size ) #NEWLINE# is_too_large = builder . icmp_signed ( '>' , builder . ashr ( allocated , two ) , new_size ) #NEWLINE# with builder . if_then ( is_too_large , likely = False ) : #NEWLINE# #INDENT# _payload_realloc ( new_size ) #NEWLINE# #UNINDENT# with builder . if_then ( is_too_small , likely = False ) : #NEWLINE# #INDENT# new_allocated = builder . add ( eight , builder . add ( new_size , builder . ashr ( new_size , two ) ) ) #NEWLINE# _payload_realloc ( new_allocated ) #NEWLINE# #UNINDENT# self . _payload . size = new_size #NEWLINE# self . set_dirty ( True )