Skip to content

Commit b166787

Browse files
committed
encoding_conversion is always true for match_in_region and select_encoding
1 parent ea1ddb7 commit b166787

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

src/main/java/org/truffleruby/core/regexp/TruffleRegexpNodes.java

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
import java.util.concurrent.ConcurrentHashMap;
1717
import java.util.concurrent.atomic.AtomicInteger;
1818

19-
import com.oracle.truffle.api.CompilerDirectives;
2019
import com.oracle.truffle.api.library.CachedLibrary;
2120
import com.oracle.truffle.api.profiles.BranchProfile;
2221
import com.oracle.truffle.api.source.Source;
@@ -240,28 +239,15 @@ public RubyRegexp createRegexp(Rope pattern) throws DeferredRaiseException {
240239
}
241240
}
242241

243-
@CoreMethod(names = "select_encoding", onSingleton = true, required = 3)
242+
@CoreMethod(names = "select_encoding", onSingleton = true, required = 2)
244243
public abstract static class SelectEncodingNode extends CoreMethodArrayArgumentsNode {
245244

246-
@Child CheckEncodingNode checkEncodingNode;
247-
248245
@Specialization(guards = "libString.isRubyString(str)")
249-
protected RubyEncoding selectEncoding(RubyRegexp re, Object str, boolean encodingConversion,
246+
protected RubyEncoding selectEncoding(RubyRegexp re, Object str,
250247
@Cached EncodingNodes.GetRubyEncodingNode getRubyEncodingNode,
251-
@Cached TruffleRegexpNodes.CheckEncodingNode checkEncodingNode,
248+
@Cached CheckEncodingNode checkEncodingNode,
252249
@CachedLibrary(limit = "2") RubyStringLibrary libString) {
253-
Encoding encoding;
254-
if (encodingConversion) {
255-
if (checkEncodingNode == null) {
256-
CompilerDirectives.transferToInterpreterAndInvalidate();
257-
checkEncodingNode = insert(CheckEncodingNode.create());
258-
}
259-
260-
encoding = checkEncodingNode.executeCheckEncoding(re, str);
261-
} else {
262-
encoding = re.regex.getEncoding();
263-
}
264-
250+
final Encoding encoding = checkEncodingNode.executeCheckEncoding(re, str);
265251
return getRubyEncodingNode.executeGetRubyEncoding(encoding);
266252
}
267253
}
@@ -429,8 +415,8 @@ protected Object matchInRegion(
429415
RubyRegexp regexp, Object string, int fromPos, int toPos, boolean atStart, int startPos,
430416
@Cached ConditionProfile encodingMismatchProfile,
431417
@Cached RopeNodes.BytesNode bytesNode,
432-
@Cached TruffleRegexpNodes.MatchNode matchNode,
433-
@Cached TruffleRegexpNodes.CheckEncodingNode checkEncodingNode,
418+
@Cached MatchNode matchNode,
419+
@Cached CheckEncodingNode checkEncodingNode,
434420
@CachedLibrary(limit = "2") RubyStringLibrary libString) {
435421
final Rope rope = libString.getRope(string);
436422
final Encoding enc = checkEncodingNode.executeCheckEncoding(regexp, string);

src/main/ruby/truffleruby/core/truffle/regexp_operations.rb

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,15 @@ def self.search_region(re, str, start_index, end_index, forward)
3131
from = end_index
3232
to = start_index
3333
end
34-
match_in_region(re, str, from, to, false, true, 0)
34+
match_in_region(re, str, from, to, false, 0)
3535
end
3636

3737
# This path is used by some string and scanner methods and allows
3838
# for at_start to be specified on the matcher. FIXME it might be
3939
# possible to refactor search region to offer the ability to
4040
# specify at start, we should investigate this at some point.
4141
def self.match_onwards(re, str, from, at_start)
42-
md = match_in_region(re, str, from, str.bytesize, at_start, true, from)
42+
md = match_in_region(re, str, from, str.bytesize, at_start, from)
4343
Primitive.matchdata_fixup_positions(md, from) if md
4444
md
4545
end
@@ -72,19 +72,19 @@ def self.match_from(re, str, pos)
7272
end
7373
end
7474

75-
def self.match_in_region(re, str, from, to, at_start, encoding_conversion, start)
75+
def self.match_in_region(re, str, from, to, at_start, start)
7676
if COMPARE_ENGINES
77-
match_in_region_compare_engines(re, str, from, to, at_start, encoding_conversion, start)
77+
match_in_region_compare_engines(re, str, from, to, at_start, start)
7878
elsif USE_TRUFFLE_REGEX
79-
match_in_region_tregex(re, str, from, to, at_start, encoding_conversion, start)
79+
match_in_region_tregex(re, str, from, to, at_start, start)
8080
else
8181
Primitive.regexp_match_in_region(re, str, from, to, at_start, start)
8282
end
8383
end
8484

85-
def self.match_in_region_compare_engines(re, str, from, to, at_start, encoding_conversion, start)
85+
def self.match_in_region_compare_engines(re, str, from, to, at_start, start)
8686
begin
87-
md1 = match_in_region_tregex(re, str, from, to, at_start, encoding_conversion, start)
87+
md1 = match_in_region_tregex(re, str, from, to, at_start, start)
8888
rescue => e
8989
md1 = e
9090
end
@@ -96,18 +96,18 @@ def self.match_in_region_compare_engines(re, str, from, to, at_start, encoding_c
9696
if self.results_match?(md1, md2)
9797
return self.return_match_data(md1)
9898
else
99-
$stderr.puts "match_in_region(/#{re}/, \"#{str}\"@#{str.encoding}, #{from}, #{to}, #{at_start}, #{encoding_conversion}, #{start}) gate"
99+
$stderr.puts "match_in_region(/#{re}/, \"#{str}\"@#{str.encoding}, #{from}, #{to}, #{at_start}, #{start}) gate"
100100
self.print_match_data(md1)
101101
$stderr.puts 'but we expected'
102102
self.print_match_data(md2)
103103
return self.return_match_data(md2)
104104
end
105105
end
106106

107-
def self.match_in_region_tregex(re, str, from, to, at_start, encoding_conversion, start)
107+
def self.match_in_region_tregex(re, str, from, to, at_start, start)
108108
bail_out = to < from || to != str.bytesize || start != 0 || from < 0
109109
if !bail_out
110-
compiled_regex = tregex_compile(re, at_start, select_encoding(re, str, encoding_conversion))
110+
compiled_regex = tregex_compile(re, at_start, select_encoding(re, str))
111111
bail_out = compiled_regex.nil?
112112
end
113113
if !bail_out

0 commit comments

Comments
 (0)