Skip to content

Commit

Permalink
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -111,7 +111,8 @@ public AddNode(RubyContext context, SourceSection sourceSection) {
@Specialization(guards = "isRubyString(other)")
public DynamicObject add(DynamicObject string, DynamicObject other) {
final Encoding enc = StringOperations.checkEncoding(getContext(), string, StringOperations.getCodeRangeable(other), this);
final DynamicObject ret = createString(StringSupport.addByteLists(StringOperations.getByteList(string), StringOperations.getByteList(other)));
final int codeRange = StringOperations.commonCodeRange(Layouts.STRING.getCodeRange(string), Layouts.STRING.getCodeRange(other));
final DynamicObject ret = Layouts.STRING.createString(getContext().getCoreLibrary().getStringFactory(), StringSupport.addByteLists(StringOperations.getByteList(string), StringOperations.getByteList(other)), codeRange, null);

if (taintResultNode == null) {
CompilerDirectives.transferToInterpreter();
Original file line number Diff line number Diff line change
@@ -189,5 +189,21 @@ public static ByteList encodeByteList(CharSequence value, Encoding encoding) {
public static ByteList getByteList(DynamicObject object) {
return Layouts.STRING.getByteList(object);
}


public static int commonCodeRange(int first, int second) {
if (first == second) {
return first;
}

if ((first == StringSupport.CR_UNKNOWN) || (second == StringSupport.CR_UNKNOWN)) {
return StringSupport.CR_UNKNOWN;
}

if ((first == StringSupport.CR_BROKEN) || (second == StringSupport.CR_BROKEN)) {
return StringSupport.CR_BROKEN;
}

// If we get this far, one must be CR_7BIT and the other must be CR_VALID, so promote to the more general code range.
return StringSupport.CR_VALID;
}
}

0 comments on commit c3ad290

Please sign in to comment.