@@ -4247,6 +4247,8 @@ private Object bytesToInum(AbstractTruffleString tstring, RubyEncoding encoding,
4247
4247
}
4248
4248
}
4249
4249
4250
+ /** The semantics of this primitive are such that the original string's byte[] should be extended without
4251
+ * negotiating the encoding. */
4250
4252
@ Primitive (name = "string_byte_append" )
4251
4253
public abstract static class StringByteAppendPrimitiveNode extends PrimitiveArrayArgumentsNode {
4252
4254
@ Specialization (guards = "libOther.isRubyString(other)" , limit = "1" )
@@ -4255,8 +4257,7 @@ protected RubyString stringByteAppend(RubyString string, Object other,
4255
4257
@ Cached RubyStringLibrary libOther ,
4256
4258
@ Cached TruffleString .ConcatNode concatNode ,
4257
4259
@ Cached TruffleString .ForceEncodingNode forceEncodingNode ) {
4258
- // The semantics of this primitive are such that the original string's byte[] should be extended without
4259
- // negotiating the encoding.
4260
+
4260
4261
var leftEncoding = libString .getEncoding (string );
4261
4262
var left = string .tstring ;
4262
4263
var right = forceEncodingNode .execute (libOther .getTString (other ), libOther .getTEncoding (other ),
@@ -4266,6 +4267,28 @@ protected RubyString stringByteAppend(RubyString string, Object other,
4266
4267
}
4267
4268
}
4268
4269
4270
+ /** The semantics of this primitive are such that the LHS string must be BINARY and then the result is BINARY as
4271
+ * well, and the RHS bytes are just appended to the LHS bytes, without encoding negotiation (which could cause the
4272
+ * LHS encoding to change). */
4273
+ @ Primitive (name = "string_binary_append" )
4274
+ public abstract static class StringBinaryAppendNode extends PrimitiveArrayArgumentsNode {
4275
+ @ Specialization (guards = "libOther.isRubyString(other)" , limit = "1" )
4276
+ protected RubyString stringBinaryAppend (RubyString string , Object other ,
4277
+ @ Cached RubyStringLibrary libString ,
4278
+ @ Cached RubyStringLibrary libOther ,
4279
+ @ Cached TruffleString .ConcatNode concatNode ,
4280
+ @ Cached TruffleString .ForceEncodingNode forceEncodingNode ) {
4281
+ if (libString .getEncoding (string ) != Encodings .BINARY ) {
4282
+ throw CompilerDirectives .shouldNotReachHere ("LHS String must be BINARY" );
4283
+ }
4284
+ var left = string .tstring ;
4285
+ var right = forceEncodingNode .execute (libOther .getTString (other ), libOther .getTEncoding (other ),
4286
+ Encodings .BINARY .tencoding );
4287
+ string .setTString (concatNode .execute (left , right , Encodings .BINARY .tencoding , true ), Encodings .BINARY );
4288
+ return string ;
4289
+ }
4290
+ }
4291
+
4269
4292
@ Primitive (name = "string_substring" , lowerFixnum = { 1 , 2 })
4270
4293
@ ImportStatic (StringGuards .class )
4271
4294
public abstract static class StringSubstringPrimitiveNode extends PrimitiveArrayArgumentsNode {
0 commit comments