Skip to content

Commit

Permalink
[Truffle] Optimize two common cases for matching regexp and string en…
Browse files Browse the repository at this point in the history
…coding.
  • Loading branch information
eregon committed Aug 7, 2016
1 parent a804329 commit 88eb5ac
Showing 1 changed file with 10 additions and 6 deletions.
Expand Up @@ -316,17 +316,21 @@ public static void setOptions(DynamicObject regexp, RegexpOptions options) {
public static Encoding checkEncoding(DynamicObject regexp, Rope str, boolean warn) {
assert RubyGuards.isRubyRegexp(regexp);

final Regex pattern = Layouts.REGEXP.getRegex(regexp);
final Encoding strEnc = str.getEncoding();
final Encoding regexEnc = Layouts.REGEXP.getRegex(regexp).getEncoding();

/*
if (str.scanForCodeRange() == StringSupport.CR_BROKEN) {
throw getRuntime().newArgumentError("invalid byte sequence in " + str.getEncoding());
}
*/
//check();
Encoding enc = str.getEncoding();
if (!enc.isAsciiCompatible()) {
if (enc != pattern.getEncoding()) {
if (strEnc == regexEnc) {
return regexEnc;
} else if (regexEnc == USASCIIEncoding.INSTANCE && str.getCodeRange() == CodeRange.CR_7BIT) {
return regexEnc;
} else if (!strEnc.isAsciiCompatible()) {
if (strEnc != regexEnc) {
//encodingMatchError(getRuntime(), pattern, enc);
}
} else if (Layouts.REGEXP.getOptions(regexp).isFixed()) {
Expand All @@ -337,14 +341,14 @@ public static Encoding checkEncoding(DynamicObject regexp, Rope str, boolean war
encodingMatchError(getRuntime(), pattern, enc);
}
*/
enc = pattern.getEncoding();
return regexEnc;
}
/*
if (warn && this.options.isEncodingNone() && enc != ASCIIEncoding.INSTANCE && str.scanForCodeRange() != StringSupport.CR_7BIT) {
getRuntime().getWarnings().warn(ID.REGEXP_MATCH_AGAINST_STRING, "regexp match /.../n against to " + enc + " string");
}
*/
return enc;
return strEnc;
}

public static void initialize(RubyContext context, DynamicObject regexp, Node currentNode, Rope setSource, int options) {
Expand Down

0 comments on commit 88eb5ac

Please sign in to comment.