@@ -2155,86 +2155,6 @@ rb_str_init(rb_execution_context_t *ec, VALUE str, VALUE orig, VALUE no_str, VAL
21552155 return str ;
21562156}
21572157
2158- /* :nodoc: */
2159- VALUE
2160- rb_str_s_new (int argc , VALUE * argv , VALUE klass )
2161- {
2162- if (klass != rb_cString ) {
2163- return rb_class_new_instance_pass_kw (argc , argv , klass );
2164- }
2165-
2166- static ID keyword_ids [2 ];
2167- VALUE orig , opt , encoding = Qnil , capacity = Qnil ;
2168- VALUE kwargs [2 ];
2169- rb_encoding * enc = NULL ;
2170-
2171- int n = rb_scan_args (argc , argv , "01:" , & orig , & opt );
2172- if (NIL_P (opt )) {
2173- return rb_class_new_instance_pass_kw (argc , argv , klass );
2174- }
2175-
2176- keyword_ids [0 ] = rb_id_encoding ();
2177- CONST_ID (keyword_ids [1 ], "capacity" );
2178- rb_get_kwargs (opt , keyword_ids , 0 , 2 , kwargs );
2179- encoding = kwargs [0 ];
2180- capacity = kwargs [1 ];
2181-
2182- if (n == 1 ) {
2183- orig = StringValue (orig );
2184- }
2185- else {
2186- orig = Qnil ;
2187- }
2188-
2189- if (UNDEF_P (encoding )) {
2190- if (!NIL_P (orig )) {
2191- encoding = rb_obj_encoding (orig );
2192- }
2193- }
2194-
2195- if (!UNDEF_P (encoding )) {
2196- enc = rb_to_encoding (encoding );
2197- }
2198-
2199- // If capacity is nil, we're basically just duping `orig`.
2200- if (UNDEF_P (capacity )) {
2201- if (NIL_P (orig )) {
2202- VALUE empty_str = str_new (klass , "" , 0 );
2203- if (enc ) {
2204- rb_enc_associate (empty_str , enc );
2205- }
2206- return empty_str ;
2207- }
2208- VALUE copy = str_duplicate (klass , orig );
2209- rb_enc_associate (copy , enc );
2210- ENC_CODERANGE_CLEAR (copy );
2211- return copy ;
2212- }
2213-
2214- long capa = 0 ;
2215- capa = NUM2LONG (capacity );
2216- if (capa < 0 ) {
2217- capa = 0 ;
2218- }
2219-
2220- if (!NIL_P (orig )) {
2221- long orig_capa = rb_str_capacity (orig );
2222- if (orig_capa > capa ) {
2223- capa = orig_capa ;
2224- }
2225- }
2226-
2227- VALUE str = str_enc_new (klass , NULL , capa , enc );
2228- STR_SET_LEN (str , 0 );
2229- TERM_FILL (RSTRING_PTR (str ), enc ? rb_enc_mbmaxlen (enc ) : 1 );
2230-
2231- if (!NIL_P (orig )) {
2232- rb_str_buf_append (str , orig );
2233- }
2234-
2235- return str ;
2236- }
2237-
22382158#ifdef NONASCII_MASK
22392159#define is_utf8_lead_byte (c ) (((c)&0xC0) != 0x80)
22402160
0 commit comments