@@ -54,7 +54,6 @@ const mp_obj_t mp_const_empty_bytes;
54
54
55
55
STATIC mp_obj_t mp_obj_new_str_iterator (mp_obj_t str );
56
56
STATIC mp_obj_t mp_obj_new_bytes_iterator (mp_obj_t str );
57
- mp_obj_t str_new (const mp_obj_type_t * type , const byte * data , uint len );
58
57
STATIC NORETURN void bad_implicit_conversion (mp_obj_t self_in );
59
58
STATIC NORETURN void arg_type_mixup ();
60
59
@@ -143,7 +142,7 @@ STATIC mp_obj_t str_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const mp_
143
142
}
144
143
GET_STR_DATA_LEN (args [0 ], str_data , str_len );
145
144
GET_STR_HASH (args [0 ], str_hash );
146
- mp_obj_str_t * o = str_new (& mp_type_str , NULL , str_len );
145
+ mp_obj_str_t * o = mp_obj_new_str_of_type (& mp_type_str , NULL , str_len );
147
146
o -> data = str_data ;
148
147
o -> hash = str_hash ;
149
148
return o ;
@@ -171,7 +170,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, uint n_args, uint n_kw, const m
171
170
}
172
171
GET_STR_DATA_LEN (args [0 ], str_data , str_len );
173
172
GET_STR_HASH (args [0 ], str_hash );
174
- mp_obj_str_t * o = str_new (& mp_type_bytes , NULL , str_len );
173
+ mp_obj_str_t * o = mp_obj_new_str_of_type (& mp_type_bytes , NULL , str_len );
175
174
o -> data = str_data ;
176
175
o -> hash = str_hash ;
177
176
return o ;
@@ -356,7 +355,7 @@ STATIC mp_obj_t str_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
356
355
nlr_raise (mp_obj_new_exception_msg (& mp_type_NotImplementedError ,
357
356
"Only slices with step=1 (aka None) are supported" ));
358
357
}
359
- return str_new (type , self_data + slice .start , slice .stop - slice .start );
358
+ return mp_obj_new_str_of_type (type , self_data + slice .start , slice .stop - slice .start );
360
359
}
361
360
#endif
362
361
uint index_val = mp_get_index (type , self_len , index , false);
@@ -447,7 +446,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
447
446
while (s < top && splits != 0 ) {
448
447
const byte * start = s ;
449
448
while (s < top && !is_ws (* s )) s ++ ;
450
- mp_obj_list_append (res , str_new (self_type , start , s - start ));
449
+ mp_obj_list_append (res , mp_obj_new_str_of_type (self_type , start , s - start ));
451
450
if (s >= top ) {
452
451
break ;
453
452
}
@@ -458,7 +457,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
458
457
}
459
458
460
459
if (s < top ) {
461
- mp_obj_list_append (res , str_new (self_type , s , top - s ));
460
+ mp_obj_list_append (res , mp_obj_new_str_of_type (self_type , s , top - s ));
462
461
}
463
462
464
463
} else {
@@ -482,7 +481,7 @@ STATIC mp_obj_t str_split(uint n_args, const mp_obj_t *args) {
482
481
}
483
482
s ++ ;
484
483
}
485
- mp_obj_list_append (res , str_new (self_type , start , s - start ));
484
+ mp_obj_list_append (res , mp_obj_new_str_of_type (self_type , start , s - start ));
486
485
if (s >= top ) {
487
486
break ;
488
487
}
@@ -537,10 +536,10 @@ STATIC mp_obj_t str_rsplit(uint n_args, const mp_obj_t *args) {
537
536
s -- ;
538
537
}
539
538
if (s < beg || splits == 0 ) {
540
- res -> items [idx ] = str_new (self_type , beg , last - beg );
539
+ res -> items [idx ] = mp_obj_new_str_of_type (self_type , beg , last - beg );
541
540
break ;
542
541
}
543
- res -> items [idx -- ] = str_new (self_type , s + sep_len , last - s - sep_len );
542
+ res -> items [idx -- ] = mp_obj_new_str_of_type (self_type , s + sep_len , last - s - sep_len );
544
543
last = s ;
545
544
if (splits > 0 ) {
546
545
splits -- ;
@@ -692,7 +691,7 @@ STATIC mp_obj_t str_uni_strip(int type, uint n_args, const mp_obj_t *args) {
692
691
assert (last_good_char_pos >= first_good_char_pos );
693
692
//+1 to accomodate the last character
694
693
machine_uint_t stripped_len = last_good_char_pos - first_good_char_pos + 1 ;
695
- return str_new (self_type , orig_str + first_good_char_pos , stripped_len );
694
+ return mp_obj_new_str_of_type (self_type , orig_str + first_good_char_pos , stripped_len );
696
695
}
697
696
698
697
STATIC mp_obj_t str_strip (uint n_args , const mp_obj_t * args ) {
@@ -1455,9 +1454,9 @@ STATIC mp_obj_t str_partitioner(mp_obj_t self_in, mp_obj_t arg, machine_int_t di
1455
1454
const byte * position_ptr = find_subbytes (str , str_len , sep , sep_len , direction );
1456
1455
if (position_ptr != NULL ) {
1457
1456
machine_uint_t position = position_ptr - str ;
1458
- result [0 ] = str_new (self_type , str , position );
1457
+ result [0 ] = mp_obj_new_str_of_type (self_type , str , position );
1459
1458
result [1 ] = arg ;
1460
- result [2 ] = str_new (self_type , str + position + sep_len , str_len - position - sep_len );
1459
+ result [2 ] = mp_obj_new_str_of_type (self_type , str + position + sep_len , str_len - position - sep_len );
1461
1460
}
1462
1461
1463
1462
return mp_obj_new_tuple (3 , result );
@@ -1641,7 +1640,7 @@ mp_obj_t mp_obj_str_builder_end(mp_obj_t o_in) {
1641
1640
return o ;
1642
1641
}
1643
1642
1644
- mp_obj_t str_new (const mp_obj_type_t * type , const byte * data , uint len ) {
1643
+ mp_obj_t mp_obj_new_str_of_type (const mp_obj_type_t * type , const byte * data , uint len ) {
1645
1644
mp_obj_str_t * o = m_new_obj (mp_obj_str_t );
1646
1645
o -> base .type = type ;
1647
1646
o -> len = len ;
@@ -1656,21 +1655,23 @@ mp_obj_t str_new(const mp_obj_type_t *type, const byte* data, uint len) {
1656
1655
}
1657
1656
1658
1657
mp_obj_t mp_obj_new_str (const char * data , uint len , bool make_qstr_if_not_already ) {
1659
- qstr q = qstr_find_strn (data , len );
1660
- if (q != MP_QSTR_NULL ) {
1661
- // qstr with this data already exists
1662
- return MP_OBJ_NEW_QSTR (q );
1663
- } else if (make_qstr_if_not_already ) {
1664
- // no existing qstr, make a new one
1658
+ if (make_qstr_if_not_already ) {
1659
+ // use existing, or make a new qstr
1665
1660
return MP_OBJ_NEW_QSTR (qstr_from_strn (data , len ));
1666
1661
} else {
1667
- // no existing qstr, don't make one
1668
- return str_new (& mp_type_str , (const byte * )data , len );
1662
+ qstr q = qstr_find_strn (data , len );
1663
+ if (q != MP_QSTR_NULL ) {
1664
+ // qstr with this data already exists
1665
+ return MP_OBJ_NEW_QSTR (q );
1666
+ } else {
1667
+ // no existing qstr, don't make one
1668
+ return mp_obj_new_str_of_type (& mp_type_str , (const byte * )data , len );
1669
+ }
1669
1670
}
1670
1671
}
1671
1672
1672
1673
mp_obj_t mp_obj_new_bytes (const byte * data , uint len ) {
1673
- return str_new (& mp_type_bytes , data , len );
1674
+ return mp_obj_new_str_of_type (& mp_type_bytes , data , len );
1674
1675
}
1675
1676
1676
1677
bool mp_obj_str_equal (mp_obj_t s1 , mp_obj_t s2 ) {
0 commit comments