Skip to content

Commit 772fa62

Browse files
committed
[GR-17457] Move MatchData byte_begin and byte_end to Primitive
PullRequest: truffleruby/2363
2 parents 3d6a4f8 + aa05719 commit 772fa62

File tree

9 files changed

+21
-25
lines changed

9 files changed

+21
-25
lines changed

lib/truffle/strscan.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ def matched?
195195
end
196196

197197
def matched_size
198-
@match.byte_end(0) - @match.byte_begin(0) if @match
198+
Primitive.match_data_byte_end(@match, 0) - Primitive.match_data_byte_begin(@match, 0) if @match
199199
end
200200

201201
def matchedsize
@@ -208,7 +208,7 @@ def post_match
208208
end
209209

210210
def pre_match
211-
@string.byteslice(0, match.byte_begin(0)) if @match
211+
@string.byteslice(0, Primitive.match_data_byte_begin(match, 0)) if @match
212212
end
213213

214214
def reset_state
@@ -317,7 +317,7 @@ def scan_internal(pattern, advance_pos, getstr, headonly)
317317
@match = Truffle::RegexpOperations.match_onwards pattern, @string, pos, headonly
318318
return nil unless @match
319319

320-
fin = @match.byte_end(0)
320+
fin = Primitive.match_data_byte_end(@match, 0)
321321

322322
@prev_pos = @pos
323323
@pos = fin if advance_pos

spec/tags/truffle/methods_tags.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ fails:Public methods on Proc should not include bound_method=
6363
fails:Public methods on Proc should not include ruby_method
6464
fails:Public methods on Proc should not include ruby_method=
6565
fails:Public methods on Proc should include hash
66-
fails:Public methods on MatchData should not include byte_begin
67-
fails:Public methods on MatchData should not include byte_end
6866
fails:Public methods on MatchData should include hash
6967
fails:Public methods on Method should include clone
7068
fails:Public methods on Method should include original_name

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

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.truffleruby.builtins.CoreMethod;
2121
import org.truffleruby.builtins.CoreMethodArrayArgumentsNode;
2222
import org.truffleruby.builtins.CoreModule;
23-
import org.truffleruby.builtins.NonStandard;
2423
import org.truffleruby.builtins.Primitive;
2524
import org.truffleruby.builtins.PrimitiveArrayArgumentsNode;
2625
import org.truffleruby.builtins.UnaryCoreMethodNode;
@@ -521,9 +520,8 @@ protected boolean inBounds(RubyMatchData matchData, int index) {
521520
}
522521
}
523522

524-
@NonStandard
525-
@CoreMethod(names = "byte_begin", required = 1, lowerFixnum = 1)
526-
public abstract static class ByteBeginNode extends CoreMethodArrayArgumentsNode {
523+
@Primitive(name = "match_data_byte_begin", lowerFixnum = 1)
524+
public abstract static class ByteBeginNode extends PrimitiveArrayArgumentsNode {
527525

528526
@Specialization(guards = "inBounds(matchData, index)")
529527
protected Object byteBegin(RubyMatchData matchData, int index) {
@@ -540,9 +538,8 @@ protected boolean inBounds(RubyMatchData matchData, int index) {
540538
}
541539
}
542540

543-
@NonStandard
544-
@CoreMethod(names = "byte_end", required = 1, lowerFixnum = 1)
545-
public abstract static class ByteEndNode extends CoreMethodArrayArgumentsNode {
541+
@Primitive(name = "match_data_byte_end", lowerFixnum = 1)
542+
public abstract static class ByteEndNode extends PrimitiveArrayArgumentsNode {
546543

547544
@Specialization(guards = "inBounds(matchData, index)")
548545
protected Object byteEnd(RubyMatchData matchData, int index) {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,8 @@ def self.path_split(str)
243243
last_match = nil
244244

245245
while match = %r!/+!.match_from(str, start)
246-
cur_start = match.byte_begin(0)
247-
cur_end = match.byte_end(0)
246+
cur_start = Primitive.match_data_byte_begin(match, 0)
247+
cur_end = Primitive.match_data_byte_end(match, 0)
248248
ret << str.byteslice(start, cur_start - start)
249249
ret << str.byteslice(cur_start, cur_end - cur_start)
250250

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ def split_type_regexp(string, pattern, limit, block)
160160

161161
collapsed = Truffle::RegexpOperations.collapsing?(match)
162162

163-
unless collapsed && (match.byte_begin(0) == last_match_end)
163+
unless collapsed && (Primitive.match_data_byte_begin(match, 0) == last_match_end)
164164
substring = Truffle::RegexpOperations.pre_match_from(match, last_match_end)
165165
empty_count = add_substring(string, ret, substring, empty_count, block)
166166

@@ -174,13 +174,13 @@ def split_type_regexp(string, pattern, limit, block)
174174
count += 1
175175
end
176176

177-
start = match.byte_end(0)
177+
start = Primitive.match_data_byte_end(match, 0)
178178
if collapsed
179179
start += 1
180180
end
181181

182182
last_match = match
183-
last_match_end = last_match.byte_end(0)
183+
last_match_end = Primitive.match_data_byte_end(last_match, 0)
184184
end
185185

186186
if last_match

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ def scan(pattern, &block)
237237
ret = block_given? ? self : []
238238

239239
while match = pattern.match_from(self, index)
240-
fin = match.byte_end(0)
240+
fin = Primitive.match_data_byte_end(match, 0)
241241

242242
if Truffle::RegexpOperations.collapsing?(match)
243243
if char = Primitive.string_find_character(self, fin)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def =~(pattern)
9696
when Regexp
9797
match_data = Truffle::RegexpOperations.search_region(pattern, str, 0, str.bytesize, true)
9898
Primitive.regexp_last_match_set(Primitive.caller_special_variables, match_data)
99-
match_data.byte_begin(0) if match_data
99+
Primitive.match_data_byte_begin(match_data, 0) if match_data
100100
when String
101101
raise TypeError, 'type mismatch: String given'
102102
else

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,14 +169,15 @@ def self.match_stats
169169
end
170170

171171
def self.collapsing?(match)
172-
match.byte_begin(0) == match.byte_end(0)
172+
Primitive.match_data_byte_begin(match, 0) == Primitive.match_data_byte_end(match, 0)
173173
end
174174

175175
def self.pre_match_from(match, idx)
176176
source = Primitive.match_data_get_source(match)
177-
return source.byteslice(0, 0) if match.byte_begin(0) == 0
177+
match_byte_begin = Primitive.match_data_byte_begin(match, 0)
178+
return source.byteslice(0, 0) if match_byte_begin == 0
178179

179-
nd = match.byte_begin(0) - 1
180+
nd = match_byte_begin - 1
180181
source.byteslice(idx, nd-idx+1)
181182
end
182183
end

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def self.gsub_internal_core(orig, pattern)
8787
ret = orig.byteslice(0, 0) # Empty string and string subclass
8888

8989
while match
90-
offset = match.byte_begin(0)
90+
offset = Primitive.match_data_byte_begin(match, 0)
9191

9292
str = Truffle::RegexpOperations.pre_match_from(match, last_end)
9393
Primitive.string_append(ret, str) if str
@@ -103,11 +103,11 @@ def self.gsub_internal_core(orig, pattern)
103103
offset += 1
104104
end
105105
else
106-
offset = match.byte_end(0)
106+
offset = Primitive.match_data_byte_end(match, 0)
107107
end
108108

109109
last_match = match
110-
last_end = match.byte_end(0)
110+
last_end = Primitive.match_data_byte_end(match, 0)
111111

112112
if String === pattern
113113
index = byte_index(orig, pattern, offset)

0 commit comments

Comments
 (0)