Permalink
Browse files

fix rubyspec failure introduced in 7bb772c

  • Loading branch information...
1 parent 7432548 commit 49a21a25be62bd4d1e9f41fc8ab5cce7ca5ffb93 @timfel timfel committed Oct 11, 2012
Showing with 28 additions and 6 deletions.
  1. +28 −6 src/kernel/bootstrap/String.rb
@@ -732,11 +732,36 @@ def _gsub_copyfrom_to(from, match_start)
end
# Generic version of gsub, for aliasing
+ # ELSE BRANCH COPIED FROM SPECIALIZED VERSION
def gsub(regex, str=nil, &block)
if str
_gsub_internal(regex, str)[0]
else
- _gsub_internal_with_block(regex, &block)
+ # if block_given?,
+ # $~ and related variables will be valid in block if
+ # blocks's home method and caller's home method are the same
+ unless block_given?
+ # updating of $~ not implemented yet on this path
+ return StringGsubEnumerator.new(self, :gsub, regex) # for 1.8.7
+ end
+ start = 0
+ out = self.class.__alloc
+ last_match = nil
+ self.__get_pattern(regex, true).__each_match_vcgl(self, 0x30) do |match|
+ last_match = match
+ out.__append_internal(self._gsub_copyfrom_to(start, match.begin(0)))
+ saveTilde = block.__fetchRubyVcGlobal(0)
+ begin
+ block.__setRubyVcGlobal(0, match)
+ out.__append_internal(block.call(match.__at(0)).to_s)
+ ensure
+ block.__setRubyVcGlobal(0, saveTilde)
+ end
+ start = match.end(0)
+ end
+ out.__append_internal(self.__copyfrom_to(start + 1, self.__size))
+ last_match.__storeRubyVcGlobal(0x20) # store into caller's $~
+ out
end
end
@@ -846,12 +871,9 @@ def __replace_match_with(match, replacement, flag=true)
out
end
-
+ # specialized version for invocation with block
+ # COPY TO ELSE BRANCH OF GENERIC VERSION ABOVE IF CHANGED
def gsub(regex, &block)
- _gsub_internal_with_block(regex, &block)
- end
-
- def _gsub_internal_with_block(regex, &block)
# if block_given?,
# $~ and related variables will be valid in block if
# blocks's home method and caller's home method are the same

0 comments on commit 49a21a2

Please sign in to comment.