提交 a03fed88 编写于 作者: Y Yves Senn

Revert "Speedup String#to"

This reverts commit 2ef1fb2c.

As described in PR #13627 this commit broke functionality when passing
a negative Fixnum to the `String#to` method:

```ruby
assert_equal "hell", s.to(-2)
```

Before the revert, this failed with:

```
  1) Failure:
StringAccessTest#test_#to_with_negative_Fixnum,_position_is_counted_from_the_end [test/core_ext/string_ext_test.rb:275]:
Expected: "hell"
  Actual: nil
```

This revert is to keep the functionality on `master` working.
If there is another way to get the performance benefit and keep
the documented functionality we can add that.

/cc @amatsuda @carlosantoniodasilva
上级 40a83d74
......@@ -59,7 +59,7 @@ def from(position)
# str.from(0).to(-1) # => "hello"
# str.from(1).to(-2) # => "ell"
def to(position)
self[0, position + 1]
self[0..position]
end
# Returns the first character. If a limit is supplied, returns a substring
......
......@@ -272,12 +272,10 @@ class StringAccessTest < ActiveSupport::TestCase
end
test "#to with negative Fixnum, position is counted from the end" do
skip "functionality was broken with 2ef1fb2c455ca53a0c1e1768f50824926ce28bd3"
assert_equal "hell", "hello".to(-2)
end
test "#from and #to can be combined" do
skip "functionality was broken with 2ef1fb2c455ca53a0c1e1768f50824926ce28bd3"
assert_equal "hello", "hello".from(0).to(-1)
assert_equal "ell", "hello".from(1).to(-2)
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册