Skip to content

Commit

Permalink
Showing 2 changed files with 15 additions and 15 deletions.
22 changes: 11 additions & 11 deletions core/src/main/java/org/jruby/RubyRegexp.java
Original file line number Diff line number Diff line change
@@ -309,7 +309,7 @@ private RubyRegexp(Ruby runtime, ByteList str, RegexpOptions options) {
this(runtime);
str.getClass();

initializeCommon19(str, str.getEncoding(), options);
regexpInitialize(str, str.getEncoding(), options);
}

// used only by the compiler/interpreter (will set the literal flag)
@@ -401,7 +401,7 @@ static RubyRegexp newDummyRegexp(Ruby runtime, Regex regex) {
// MRI: rb_reg_new_str
public static RubyRegexp newRegexpFromStr(Ruby runtime, RubyString s, int options) {
RubyRegexp re = (RubyRegexp)runtime.getRegexp().allocate();
re.initializeCommon19(s, RegexpOptions.fromJoniOptions(options));
re.regexpInitializeString(s, RegexpOptions.fromJoniOptions(options));
return re;
}

@@ -886,7 +886,7 @@ public IRubyObject initialize_copy(IRubyObject re) {
RubyRegexp regexp = (RubyRegexp)re;
regexp.check();

return initializeCommon19(regexp.str, regexp.str.getEncoding(), regexp.getOptions());
return regexpInitialize(regexp.str, regexp.str.getEncoding(), regexp.getOptions());
}

private int objectAsJoniOptions(IRubyObject arg) {
@@ -911,7 +911,7 @@ public IRubyObject initialize_m(IRubyObject arg0, IRubyObject arg1, IRubyObject
@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE)
public IRubyObject initialize_m19(IRubyObject arg) {
if (arg instanceof RubyRegexp) return initializeByRegexp19((RubyRegexp)arg);
return initializeCommon19(arg.convertToString(), new RegexpOptions());
return regexpInitializeString(arg.convertToString(), new RegexpOptions());
}

@JRubyMethod(name = "initialize", visibility = Visibility.PRIVATE)
@@ -921,7 +921,7 @@ public IRubyObject initialize_m19(IRubyObject arg0, IRubyObject arg1) {
return initializeByRegexp19((RubyRegexp)arg0);
}

return initializeCommon19(arg0.convertToString(),
return regexpInitializeString(arg0.convertToString(),
RegexpOptions.fromJoniOptions(objectAsJoniOptions(arg1)));
}

@@ -938,12 +938,12 @@ public IRubyObject initialize_m19(IRubyObject arg0, IRubyObject arg1, IRubyObjec
ByteList kcodeBytes = arg2.convertToString().getByteList();
if ((kcodeBytes.getRealSize() > 0 && kcodeBytes.getUnsafeBytes()[kcodeBytes.getBegin()] == 'n') ||
(kcodeBytes.getRealSize() > 1 && kcodeBytes.getUnsafeBytes()[kcodeBytes.getBegin() + 1] == 'N')) {
return initializeCommon19(arg0.convertToString().getByteList(), ASCIIEncoding.INSTANCE, newOptions);
return regexpInitialize(arg0.convertToString().getByteList(), ASCIIEncoding.INSTANCE, newOptions);
} else {
getRuntime().getWarnings().warn("encoding option is ignored - " + kcodeBytes);
}
}
return initializeCommon19(arg0.convertToString(), newOptions);
return regexpInitializeString(arg0.convertToString(), newOptions);
}

private IRubyObject initializeByRegexp19(RubyRegexp regexp) {
@@ -952,11 +952,11 @@ private IRubyObject initializeByRegexp19(RubyRegexp regexp) {
// but it did come from one.
RegexpOptions newOptions = (RegexpOptions) regexp.getOptions().clone();
newOptions.setLiteral(false);
return initializeCommon19(regexp.str, regexp.getEncoding(), newOptions);
return regexpInitialize(regexp.str, regexp.getEncoding(), newOptions);
}

// rb_reg_initialize_str
private RubyRegexp initializeCommon19(RubyString str, RegexpOptions options) {
private RubyRegexp regexpInitializeString(RubyString str, RegexpOptions options) {
if (isLiteral()) throw getRuntime().newSecurityError("can't modify literal regexp");
ByteList bytes = str.getByteList();
Encoding enc = bytes.getEncoding();
@@ -968,11 +968,11 @@ private RubyRegexp initializeCommon19(RubyString str, RegexpOptions options) {
enc = ASCIIEncoding.INSTANCE;
}
}
return initializeCommon19(bytes, enc, options);
return regexpInitialize(bytes, enc, options);
}

// rb_reg_initialize
private RubyRegexp initializeCommon19(ByteList bytes, Encoding enc, RegexpOptions options) {
public RubyRegexp regexpInitialize(ByteList bytes, Encoding enc, RegexpOptions options) {
Ruby runtime = getRuntime();
this.options = options;

Original file line number Diff line number Diff line change
@@ -289,11 +289,13 @@ private IRubyObject unmarshalRegexp(MarshalState state) throws IOException {
byte opts = readSignedByte();
RegexpOptions reOpts = RegexpOptions.fromJoniOptions(opts);

RubyRegexp regexp = (RubyRegexp) runtime.getRegexp().allocate();
registerLinkTarget(regexp);

IRubyObject ivarHolder = null;

if (state.isIvarWaiting()) {
RubyString tmpStr = RubyString.newString(runtime, byteList);
registerLinkTarget(tmpStr);
defaultVariablesUnmarshal(tmpStr);
byteList = tmpStr.getByteList();
state.setIvarWaiting(false);
@@ -351,14 +353,12 @@ private IRubyObject unmarshalRegexp(MarshalState state) throws IOException {
byteList.setRealSize(dst - ptr);
}

RubyRegexp regexp = RubyRegexp.newRegexp(runtime, byteList, reOpts);
regexp.regexpInitialize(byteList, byteList.getEncoding(), reOpts);

if (ivarHolder != null) {
ivarHolder.getInstanceVariables().copyInstanceVariablesInto(regexp);
}

registerLinkTarget(regexp);

return regexp;
}

0 comments on commit 19b74b2

Please sign in to comment.