summaryrefslogtreecommitdiffhomepage
path: root/mrblib
diff options
context:
space:
mode:
authordearblue <[email protected]>2019-05-21 22:02:11 +0900
committerdearblue <[email protected]>2019-06-29 14:41:43 +0900
commit0d452073f46fc46496200db610ce785e514cdb65 (patch)
tree640f9694ad053ebd19d14c5a9fb621d97adedb84 /mrblib
parent40030a5dbc2b76bbd9563cdfc6389ab672312b70 (diff)
downloadmruby-0d452073f46fc46496200db610ce785e514cdb65.tar.gz
mruby-0d452073f46fc46496200db610ce785e514cdb65.zip
Replace `String#[]=` method by C implements
The purpose is to eliminate string objects that are temporarily created during processing.
Diffstat (limited to 'mrblib')
-rw-r--r--mrblib/string.rb54
1 files changed, 0 insertions, 54 deletions
diff --git a/mrblib/string.rb b/mrblib/string.rb
index b0fe4033e..c26cdb1e2 100644
--- a/mrblib/string.rb
+++ b/mrblib/string.rb
@@ -177,60 +177,6 @@ class String
self
end
- ##
- # Modify +self+ by replacing the content of +self+.
- # The portion of the string affected is determined using the same criteria as +String#[]+.
- def []=(*args)
- anum = args.size
- if anum == 2
- pos, value = args[0], args[1].__to_str
- case pos
- when String
- posnum = self.index(pos)
- if posnum
- b = self[0, posnum]
- a = self[(posnum + pos.length)..-1]
- self.replace([b, value, a].join(''))
- else
- raise IndexError, "string not matched"
- end
- when Range
- head = pos.begin
- tail = pos.end
- tail += self.length if tail < 0
- unless pos.exclude_end?
- tail += 1
- end
- return self[head, tail-head]=value
- else
- pos = pos.__to_int
- pos += self.length if pos < 0
- if pos < 0 || pos > self.length
- raise IndexError, "index #{args[0]} out of string"
- end
- b = self[0, pos]
- a = self[pos + 1..-1]
- self.replace([b, value, a].join(''))
- end
- return value
- elsif anum == 3
- pos, len, value = args[0].__to_int, args[1].__to_int, args[2].__to_str
- pos += self.length if pos < 0
- if pos < 0 || pos > self.length
- raise IndexError, "index #{args[0]} out of string"
- end
- if len < 0
- raise IndexError, "negative length #{len}"
- end
- b = self[0, pos]
- a = self[pos + len..-1]
- self.replace([b, value, a].join(''))
- return value
- else
- raise ArgumentError, "wrong number of arguments (#{anum} for 2..3)"
- end
- end
-
# those two methods requires Regexp that is optional in mruby
##
# ISO 15.2.10.5.3