Skip to content

Commit

Permalink
Showing 3 changed files with 80 additions and 83 deletions.
Original file line number Diff line number Diff line change
@@ -1862,10 +1862,7 @@ public RubyNode visitInstVarNode(org.jruby.ast.InstVarNode node) {
return addNewlineIfNeeded(node, ret);
}
} else if (path.equals(corePath + "rubinius/bootstrap/string.rb") || path.equals(corePath + "rubinius/common/string.rb")) {
if (name.equals("@num_bytes")) {
ret = StringNodesFactory.ByteSizeNodeFactory.create(context, sourceSection, new RubyNode[]{ self });
return addNewlineIfNeeded(node, ret);
} else if (name.equals("@data")) {
if (name.equals("@data")) {
ret = StringNodesFactory.DataNodeFactory.create(context, sourceSection, new RubyNode[]{ self });
return addNewlineIfNeeded(node, ret);
}
14 changes: 7 additions & 7 deletions truffle/src/main/ruby/core/rubinius/bootstrap/string.rb
Original file line number Diff line number Diff line change
@@ -68,29 +68,29 @@ def byteslice(index_or_range, length=undefined)

if index_or_range.kind_of? Range
index = Rubinius::Type.coerce_to index_or_range.begin, Fixnum, :to_int
index += @num_bytes if index < 0
return if index < 0 or index > @num_bytes
index += bytesize if index < 0
return if index < 0 or index > bytesize

finish = Rubinius::Type.coerce_to index_or_range.end, Fixnum, :to_int
finish += @num_bytes if finish < 0
finish += bytesize if finish < 0

finish += 1 unless index_or_range.exclude_end?
length = finish - index

return byteslice 0, 0 if length < 0
else
index = Rubinius::Type.coerce_to index_or_range, Fixnum, :to_int
index += @num_bytes if index < 0
index += bytesize if index < 0

if undefined.equal?(length)
return if index == @num_bytes
return if index == bytesize
length = 1
else
length = Rubinius::Type.coerce_to length, Fixnum, :to_int
return if length < 0
end

return if index < 0 or index > @num_bytes
return if index < 0 or index > bytesize
end

byteslice index, length
@@ -102,7 +102,7 @@ def find_character(offset)
end

def num_bytes
@num_bytes
bytesize
end

def byte_append(str)
144 changes: 72 additions & 72 deletions truffle/src/main/ruby/core/rubinius/common/string.rb
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ def *(num)
raise ArgumentError, "unable to multiple negative times (#{num})"
end

str = self.class.pattern num * @num_bytes, self
str = self.class.pattern num * bytesize, self
return str
end

@@ -119,15 +119,15 @@ def ==(other)
return false
end

return false unless @num_bytes == other.bytesize
return false unless bytesize == other.bytesize
return false unless Encoding.compatible?(self, other)
return @data.compare_bytes(other.__data__, @num_bytes, other.bytesize) == 0
return @data.compare_bytes(other.__data__, bytesize, other.bytesize) == 0
end

def =~(pattern)
case pattern
when Regexp
match_data = pattern.search_region(self, 0, @num_bytes, true)
match_data = pattern.search_region(self, 0, bytesize, true)
Regexp.last_match = match_data
return match_data.begin(0) if match_data
when String
@@ -156,7 +156,7 @@ def [](index, other = undefined)

case index
when Regexp
match_data = index.search_region(self, 0, @num_bytes, true)
match_data = index.search_region(self, 0, bytesize, true)
Regexp.last_match = match_data
if match_data
result = match_data.to_s
@@ -190,7 +190,7 @@ def [](index, other = undefined)
alias_method :slice, :[]

def capitalize
return dup if @num_bytes == 0
return dup if bytesize == 0

str = transform(Rubinius::CType::Lowered)

@@ -215,8 +215,8 @@ def capitalize!

def casecmp(to)
to = StringValue(to)
order = @num_bytes - to.num_bytes
size = order < 0 ? @num_bytes : to.num_bytes
order = bytesize - to.num_bytes
size = order < 0 ? bytesize : to.num_bytes

ctype = Rubinius::CType

@@ -251,12 +251,12 @@ def chop
def count(*strings)
raise ArgumentError, "wrong number of Arguments" if strings.empty?

return 0 if @num_bytes == 0
return 0 if bytesize == 0

table = count_table(*strings).__data__

count = bytes = 0
while bytes < @num_bytes
while bytes < bytesize
count += 1 if table[@data[bytes]] == 1
bytes += find_character(bytes).num_bytes
end
@@ -291,15 +291,15 @@ def delete!(*strings)
i = 0
j = -1

while i < @num_bytes
while i < bytesize
c = @data[i]
unless table[c] == 1
@data[j+=1] = c
end
i += 1
end

if (j += 1) < @num_bytes
if (j += 1) < bytesize
self.num_bytes = j
self
else
@@ -308,14 +308,14 @@ def delete!(*strings)
end

def downcase
return dup if @num_bytes == 0
return dup if bytesize == 0
transform(Rubinius::CType::Lowered)
end

def downcase!
Rubinius.check_frozen

return if @num_bytes == 0
return if bytesize == 0

str = transform(Rubinius::CType::Lowered)

@@ -330,7 +330,7 @@ def each_char
return to_enum(:each_char) { size } unless block_given?

bytes = 0
while bytes < @num_bytes
while bytes < bytesize
char = find_character(bytes)
yield char
bytes += char.num_bytes
@@ -342,15 +342,15 @@ def each_char
def each_byte
return to_enum(:each_byte) { bytesize } unless block_given?
i = 0
while i < @num_bytes do
while i < bytesize do
yield @data.get_byte(i)
i += 1
end
self
end

def empty?
@num_bytes == 0
bytesize == 0
end

def end_with?(*suffixes)
@@ -366,9 +366,9 @@ def end_with?(*suffixes)
def eql?(other)
Rubinius.primitive :string_equal

return false unless other.kind_of?(String) && other.bytesize == @num_bytes
return false unless other.kind_of?(String) && other.bytesize == bytesize
return false unless Encoding.compatible?(self, other)
return @data.compare_bytes(other.__data__, @num_bytes, other.bytesize) == 0
return @data.compare_bytes(other.__data__, bytesize, other.bytesize) == 0
end

# This method is specifically part of 1.9 but we enable it in 1.8 also
@@ -534,7 +534,7 @@ def squeeze(*strings)
end

def squeeze!(*strings)
return if @num_bytes == 0
return if bytesize == 0

table = count_table(*strings).__data__
self.modify!
@@ -543,15 +543,15 @@ def squeeze!(*strings)
j = 0
last = @data[0]

while i < @num_bytes
while i < bytesize
c = @data[i]
unless c == last and table[c] == 1
@data[j+=1] = last = c
end
i += 1
end

if (j += 1) < @num_bytes
if (j += 1) < bytesize
self.num_bytes = j
self
else
@@ -588,7 +588,7 @@ def sum(bits=16)
i = -1
sum = 0

sum += @data[i] while (i += 1) < @num_bytes
sum += @data[i] while (i += 1) < bytesize
if bits > 0
sum & ((1 << bits) - 1)
else
@@ -603,14 +603,14 @@ def swapcase

def swapcase!
self.modify!
return if @num_bytes == 0
return if bytesize == 0

modified = false

ctype = Rubinius::CType

i = 0
while i < @num_bytes
while i < bytesize
c = @data[i]
if ctype.islower(c)
@data[i] = ctype.toupper!(c)
@@ -676,15 +676,15 @@ def upcase
end

def upcase!
return if @num_bytes == 0
return if bytesize == 0
self.modify!

modified = false

ctype = Rubinius::CType

i = 0
while i < @num_bytes
while i < bytesize
c = @data[i]
if ctype.islower(c)
@data[i] = ctype.toupper!(c)
@@ -698,16 +698,16 @@ def upcase!

def to_sub_replacement(result, match)
index = 0
while index < @num_bytes
while index < bytesize
current = index
while current < @num_bytes && @data[current] != 92 # ?\\
while current < bytesize && @data[current] != 92 # ?\\
current += 1
end
result.append(byteslice(index, current - index))
break if current == @num_bytes
break if current == bytesize

# found backslash escape, looking next
if current == @num_bytes - 1
if current == bytesize - 1
result.append("\\") # backslash at end of string
break
end
@@ -768,7 +768,7 @@ def apply_and!(other)
def compare_substring(other, start, size)
Rubinius.primitive :string_compare_substring

if start > @num_bytes || start + @num_bytes < 0
if start > bytesize || start + bytesize < 0
raise IndexError, "index #{start} out of string"
end
raise PrimitiveFailure, "String#compare_substring primitive failed"
@@ -840,19 +840,19 @@ def subpattern(pattern, capture)

def prefix?(other)
size = other.size
return false if size > @num_bytes
return false if size > bytesize
other.compare_substring(self, 0, size) == 0
end

def suffix?(other)
size = other.size
return false if size > @num_bytes
return false if size > bytesize
other.compare_substring(self, -size, size) == 0
end

def shorten!(size)
self.modify!
return if @num_bytes == 0
return if bytesize == 0
self.num_bytes -= size
end

@@ -1360,11 +1360,11 @@ def slice!(one, two=undefined)
def succ!
self.modify!

return self if @num_bytes == 0
return self if bytesize == 0

carry = nil
last_alnum = 0
start = @num_bytes - 1
start = bytesize - 1

ctype = Rubinius::CType

@@ -1429,17 +1429,17 @@ def to_r

def rstrip!
Rubinius.check_frozen
return if @num_bytes == 0
return if bytesize == 0

stop = @num_bytes - 1
stop = bytesize - 1

ctype = Rubinius::CType

while stop >= 0 && (@data[stop] == 0 || ctype.isspace(@data[stop]))
stop -= 1
end

return if (stop += 1) == @num_bytes
return if (stop += 1) == bytesize

modify!
self.num_bytes = stop
@@ -1448,21 +1448,21 @@ def rstrip!

def lstrip!
Rubinius.check_frozen
return if @num_bytes == 0
return if bytesize == 0

start = 0

ctype = Rubinius::CType

while start < @num_bytes && ctype.isspace(@data[start])
while start < bytesize && ctype.isspace(@data[start])
start += 1
end

return if start == 0

modify!
self.num_bytes -= start
@data.move_bytes start, @num_bytes, 0
@data.move_bytes start, bytesize, 0
self
end

@@ -1471,7 +1471,7 @@ def chop!

m = Rubinius::Mirror.reflect self

bytes = m.previous_byte_index @num_bytes
bytes = m.previous_byte_index bytesize
return unless bytes

chr = chr_at bytes
@@ -1505,7 +1505,7 @@ def chomp!(sep=undefined)
m = Rubinius::Mirror.reflect self

if sep == DEFAULT_RECORD_SEPARATOR
return unless bytes = m.previous_byte_index(@num_bytes)
return unless bytes = m.previous_byte_index(bytesize)

chr = chr_at bytes
return unless chr.ascii?
@@ -1525,8 +1525,8 @@ def chomp!(sep=undefined)
return
end
elsif sep.size == 0
return if @num_bytes == 0
bytes = @num_bytes
return if bytesize == 0
bytes = bytesize

while i = m.previous_byte_index(bytes)
chr = chr_at i
@@ -1542,14 +1542,14 @@ def chomp!(sep=undefined)
end
end

return if bytes == @num_bytes
return if bytes == bytesize
else
size = sep.size
return if size > @num_bytes
return if size > bytesize

# TODO: Move #compare_substring to mirror.
return unless sep.compare_substring(self, -size, size) == 0
bytes = @num_bytes - size
bytes = bytesize - size
end

# We do not need to dup the data, so don't use #modify!
@@ -1625,7 +1625,7 @@ def each_line(sep=$/)

pos = 0

size = @num_bytes
size = bytesize
orig_data = @data

# If the separator is empty, we're actually in paragraph mode. This
@@ -1639,28 +1639,28 @@ def each_line(sep=$/)
nxt = find_string(sep, pos)
break unless nxt

while @data[nxt] == 10 and nxt < @num_bytes
while @data[nxt] == 10 and nxt < bytesize
nxt += 1
end

match_size = nxt - pos

# string ends with \n's
break if pos == @num_bytes
break if pos == bytesize

str = byteslice pos, match_size
yield str unless str.empty?

# detect mutation within the block
if !@data.equal?(orig_data) or @num_bytes != size
if !@data.equal?(orig_data) or bytesize != size
raise RuntimeError, "string modified while iterating"
end

pos = nxt
end

# No more separates, but we need to grab the last part still.
fin = byteslice pos, @num_bytes - pos
fin = byteslice pos, bytesize - pos
yield fin if fin and !fin.empty?

else
@@ -1681,7 +1681,7 @@ def each_line(sep=$/)
end

# No more separates, but we need to grab the last part still.
fin = unmodified_self.byteslice pos, @num_bytes - pos
fin = unmodified_self.byteslice pos, bytesize - pos
yield fin unless fin.empty?
end

@@ -1727,13 +1727,13 @@ def gsub(pattern, replacement=undefined)
end

pattern = Rubinius::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
match = pattern.search_region(self, 0, @num_bytes, true)
match = pattern.search_region(self, 0, bytesize, true)

unless match
Regexp.last_match = nil
end

orig_len = @num_bytes
orig_len = bytesize
orig_data = @data

last_end = 0
@@ -1764,7 +1764,7 @@ def gsub(pattern, replacement=undefined)

ret.append val

if !@data.equal?(orig_data) or @num_bytes != orig_len
if !@data.equal?(orig_data) or bytesize != orig_len
raise RuntimeError, "string modified"
end
else
@@ -1795,7 +1795,7 @@ def gsub(pattern, replacement=undefined)

Regexp.last_match = last_match

str = byteslice(last_end, @num_bytes-last_end+1)
str = byteslice(last_end, bytesize-last_end+1)
if str
ret.append str
end
@@ -1836,14 +1836,14 @@ def gsub!(pattern, replacement=undefined)
end

pattern = Rubinius::Type.coerce_to_regexp(pattern, true) unless pattern.kind_of? Regexp
match = pattern.search_region(self, 0, @num_bytes, true)
match = pattern.search_region(self, 0, bytesize, true)

unless match
Regexp.last_match = nil
return nil
end

orig_len = @num_bytes
orig_len = bytesize
orig_data = @data

last_end = 0
@@ -1874,7 +1874,7 @@ def gsub!(pattern, replacement=undefined)

ret.append val

if !@data.equal?(orig_data) or @num_bytes != orig_len
if !@data.equal?(orig_data) or bytesize != orig_len
raise RuntimeError, "string modified"
end
else
@@ -1905,7 +1905,7 @@ def gsub!(pattern, replacement=undefined)

Regexp.last_match = last_match

str = byteslice(last_end, @num_bytes-last_end+1)
str = byteslice(last_end, bytesize-last_end+1)
if str
ret.append str
end
@@ -2371,7 +2371,7 @@ def insert(index, other)
end

osize = other.bytesize
size = @num_bytes + osize
size = bytesize + osize
str = self.class.pattern size, "\0"

self_m = Rubinius::Mirror.reflect self
@@ -2381,13 +2381,13 @@ def insert(index, other)
@hash_value = nil

m = Rubinius::Mirror.reflect str
if index == @num_bytes
m.copy_from self, 0, @num_bytes, 0
m.copy_from other, 0, osize, @num_bytes
if index == bytesize
m.copy_from self, 0, bytesize, 0
m.copy_from other, 0, osize, bytesize
else
m.copy_from self, 0, index, 0 if index > 0
m.copy_from other, 0, osize, index
m.copy_from self, index, @num_bytes - index, index + osize
m.copy_from self, index, bytesize - index, index + osize
end

self.num_bytes = size
@@ -2403,7 +2403,7 @@ def tr_trans(source, replacement, squeeze)
replacement = StringValue(replacement).dup

return delete!(source) if replacement.empty?
return if @num_bytes == 0
return if bytesize == 0

invert = source[0] == ?^ && source.length > 1

@@ -2478,7 +2478,7 @@ def tr_trans(source, replacement, squeeze)
i += 1
end

destination.num_bytes = byte_size if byte_size < @num_bytes
destination.num_bytes = byte_size if byte_size < bytesize
else
i = 0
each_char do |chr|
@@ -2506,7 +2506,7 @@ def tr_trans(source, replacement, squeeze)

def <=>(other)
if other.kind_of?(String)
result = @data.compare_bytes(other.__data__, @num_bytes, other.bytesize)
result = @data.compare_bytes(other.__data__, bytesize, other.bytesize)

if result == 0
if Encoding.compatible?(self, other)

0 comments on commit 5cd1ca7

Please sign in to comment.