Skip to content

Commit e0ef0b2

Browse files
committed
[GR-17457] Remove extra methods Regexp#{match_from, option_to_string}
PullRequest: truffleruby/2368
2 parents cc3deb1 + e4071df commit e0ef0b2

File tree

6 files changed

+15
-22
lines changed

6 files changed

+15
-22
lines changed

spec/tags/truffle/methods_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,6 @@ fails:Public methods on Method should include clone
6868
fails:Public methods on Method should include original_name
6969
fails:Public methods on UnboundMethod should include clone
7070
fails:Public methods on UnboundMethod should include original_name
71-
fails:Public methods on Regexp should not include match_from
72-
fails:Public methods on Regexp should not include option_to_string
7371
fails:Public methods on Struct should include filter
7472
fails:Public methods on Symbol should not include eql?
7573
fails:Public methods on Symbol should not include hash

src/main/ruby/truffleruby/core/dir_glob.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ def self.path_split(str)
245245

246246
last_match = nil
247247

248-
while match = %r!/+!.match_from(str, start)
248+
while match = Truffle::RegexpOperations.match_from(%r!/+!, str, start)
249249
cur_start = Primitive.match_data_byte_begin(match, 0)
250250
cur_end = Primitive.match_data_byte_end(match, 0)
251251
ret << str.byteslice(start, cur_start - start)

src/main/ruby/truffleruby/core/regexp.rb

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ def ===(other)
191191
end
192192
end
193193

194-
if match = match_from(other, 0)
194+
if match = Truffle::RegexpOperations.match_from(self, other, 0)
195195
Primitive.regexp_last_match_set(Primitive.caller_special_variables, match)
196196
true
197197
else
@@ -211,7 +211,7 @@ def eql?(other)
211211
def inspect
212212
# the regexp matches any / that is after anything except for a \
213213
escape = source.gsub(%r!(\\.)|/!) { $1 || '\/' }
214-
str = "/#{escape}/#{option_to_string(options)}"
214+
str = "/#{escape}/#{Truffle::RegexpOperations.option_to_string(options)}"
215215
str << 'n' if (options & NOENCODING) > 0
216216
str
217217
end
@@ -236,19 +236,6 @@ def casefold?
236236
(options & IGNORECASE) > 0 ? true : false
237237
end
238238

239-
def match_from(str, count)
240-
return nil unless str
241-
Truffle::RegexpOperations.search_region(self, str, count, str.bytesize, true)
242-
end
243-
244-
def option_to_string(option)
245-
string = +''
246-
string << 'm' if (option & MULTILINE) > 0
247-
string << 'i' if (option & IGNORECASE) > 0
248-
string << 'x' if (option & EXTENDED) > 0
249-
string
250-
end
251-
252239
#
253240
# call-seq:
254241
# rxp.named_captures => hash

src/main/ruby/truffleruby/core/string.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def scan(pattern, &block)
236236
last_match = nil
237237
ret = block_given? ? self : []
238238

239-
while match = pattern.match_from(self, index)
239+
while match = Truffle::RegexpOperations.match_from(pattern, self, index)
240240
fin = Primitive.match_data_byte_end(match, 0)
241241

242242
if Truffle::RegexpOperations.collapsing?(match)
@@ -681,7 +681,7 @@ def sub!(pattern, replacement=undefined, &block)
681681
end
682682

683683
pattern = Truffle::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
684-
match = pattern.match_from(self, 0)
684+
match = Truffle::RegexpOperations.match_from(pattern, self, 0)
685685

686686
Primitive.regexp_last_match_set(Primitive.proc_special_variables(block), match) if block
687687
Primitive.regexp_last_match_set(Primitive.caller_special_variables, match)
@@ -1291,7 +1291,7 @@ def index(str, start=undefined)
12911291
Primitive.encoding_ensure_compatible self, str
12921292

12931293
start = Primitive.string_byte_index_from_char_index(self, start)
1294-
if match = str.match_from(self, start)
1294+
if match = Truffle::RegexpOperations.match_from(str, self, start)
12951295
Primitive.regexp_last_match_set(Primitive.caller_special_variables, match)
12961296
return match.begin(0)
12971297
else

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,14 @@ def self.match_stats
168168
Hash[*match_stats_array]
169169
end
170170

171+
def self.option_to_string(option)
172+
string = +''
173+
string << 'm' if (option & Regexp::MULTILINE) > 0
174+
string << 'i' if (option & Regexp::IGNORECASE) > 0
175+
string << 'x' if (option & Regexp::EXTENDED) > 0
176+
string
177+
end
178+
171179
def self.collapsing?(match)
172180
Primitive.match_data_byte_begin(match, 0) == Primitive.match_data_byte_end(match, 0)
173181
end

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ def self.gsub_internal_core(orig, pattern)
113113
index = byte_index(orig, pattern, offset)
114114
match = index ? Primitive.matchdata_create_single_group(pattern, orig.dup, index, index + pattern.bytesize) : nil
115115
else
116-
match = pattern.match_from orig, offset
116+
match = Truffle::RegexpOperations.match_from(pattern, orig, offset)
117117
end
118118
end
119119

0 commit comments

Comments
 (0)