Skip to content

Commit

Permalink
Pass non-null encodings to NegotiateCompatibleEncodingNode
Browse files Browse the repository at this point in the history
  • Loading branch information
eregon committed Sep 25, 2024
1 parent 377bc14 commit c10f15e
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions src/main/java/org/truffleruby/core/encoding/EncodingNodes.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ protected static RubyEncoding compatibleEncodingForStrings(AbstractTruffleString
}

// MRI: enc_compatible_latter
/** Use {@link NegotiateCompatibleStringEncodingNode} instead if both arguments are always Strings, for footprint */
/** Use {@link NegotiateCompatibleStringEncodingNode} instead, this should only be used for
* {@code Encoding.compatible?} */
@GenerateCached(false)
@GenerateInline
public abstract static class NegotiateCompatibleEncodingNode extends RubyBaseNode {
Expand All @@ -173,6 +174,9 @@ static RubyEncoding negotiateEncoding(
@Cached InlinedConditionProfile objectStringProfile,
@Cached(inline = false) TruffleString.GetByteCodeRangeNode codeRangeNode,
@Cached NegotiateCompatibleStringEncodingNode negotiateForStringsNode) {
assert firstEncoding != null;
assert secondEncoding != null;

if (equalEncodingsProfile.profile(node, firstEncoding == secondEncoding)) {
return firstEncoding;
}
Expand All @@ -186,7 +190,7 @@ static RubyEncoding negotiateEncoding(
libSecond.getTString(node, second), secondEncoding);
}

if (incompatibleProfile.profile(node, firstEncoding == null || secondEncoding == null ||
if (incompatibleProfile.profile(node,
!firstEncoding.isAsciiCompatible || !secondEncoding.isAsciiCompatible)) {
return null;
}
Expand Down Expand Up @@ -241,10 +245,17 @@ public static CompatibleQueryNode create() {
Object isCompatible(Object first, Object second,
@Cached NegotiateCompatibleEncodingNode negotiateCompatibleEncodingNode,
@Cached ToRubyEncodingNode toRubyEncodingNode,
@Cached InlinedConditionProfile nullEncodingProfile,
@Cached InlinedConditionProfile noNegotiatedEncodingProfile) {
final var firstEncoding = toRubyEncodingNode.execute(this, first);
final var secondEncoding = toRubyEncodingNode.execute(this, second);
final RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode.execute(this, first,

var firstEncoding = toRubyEncodingNode.execute(this, first);
var secondEncoding = toRubyEncodingNode.execute(this, second);

if (nullEncodingProfile.profile(this, firstEncoding == null || secondEncoding == null)) {
return nil;
}

RubyEncoding negotiatedEncoding = negotiateCompatibleEncodingNode.execute(this, first,
firstEncoding, second, secondEncoding);

if (noNegotiatedEncodingProfile.profile(this, negotiatedEncoding == null)) {
Expand Down

0 comments on commit c10f15e

Please sign in to comment.