------------KCp9piFTOi5tPjFIS3F3Sk
Content-Type: text/plain; format=flowed; delsp=yes; charset=utf-8
Content-Transfer-Encoding: 7bit

On Fri, 12 Sep 2008 02:16:51 +1000, NARUSE, Yui <naruse / airemix.jp> wrote:

>
> If you split your patch into small atomic patches,
> your patch will be merged rapidly.
>

Unfortunately this is very time consuming because string.c is changing  
every day lately!
Some of the things in my previous patch have already been done by Matz.

As a start I have attached 2 "atomic" patches to string.c. These are:

substr.pat:
Improves the speed of rb_str_substr(), mainly for single byte encodings,  
and also (less so) for fixed-width char multi-byte encodings.
rb_str_substr is used frequently so even minor improvement in speed is  
good.

split.pat:
Improves the speed of String#split when the parameter is a string (at  
least twice as fast).
Note: this patch breaks the test suite but only because of exceptions  
raised. The new implementation will NOT raise an error when running  
s.split(s2) when s is a broken string, This is COMPATIBLE with the other  
string methods, but INCOMPATIBLE with the previous split implementation  
which converted s2 to a regexp.

I'll try to get the other things I have done to you later.

Cheers
Mike


------------KCp9piFTOi5tPjFIS3F3Sk
Content-Disposition: attachment; filename=substr.pat
Content-Type: application/octet-stream; name=substr.pat
Content-Transfer-Encoding: Base64

SW5kZXg6IHN0cmluZy5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIHN0cmluZy5j
CShyZXZpc2lvbiAxOTM3NCkKKysrIHN0cmluZy5jCSh3b3JraW5nIGNvcHkpCkBA
IC0xMTIsNyArMTEyLDcgQEAKIAogI2RlZmluZSBTVFJfRU5DX0dFVChzdHIpIHJi
X2VuY19mcm9tX2luZGV4KEVOQ09ESU5HX0dFVChzdHIpKQogCi1zdGF0aWMgaW50
CitzdGF0aWMgaW5saW5lIGludAogc2luZ2xlX2J5dGVfb3B0aW1pemFibGUoVkFM
VUUgc3RyKQogewogICAgIHJiX2VuY29kaW5nICplbmM7CkBAIC0xMTk0LDcgKzEx
OTQsNyBAQAogICAgIHJldHVybiAoY2hhciopcDsKIH0KIA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SAgICBsZW4gPSAwOworCX0K
KyAgICAgICAgZWxzZSBpZiAobGVuICogY2hhcl9zeiA+IGUgLSBwKQogICAgICAg
ICAgICAgbGVuID0gZSAtIHA7CiAgICAgICAgIGVsc2UKLQkgICAgbGVuICo9IHJi
X2VuY19tYm1heGxlbihlbmMpOworCSAgICBsZW4gKj0gY2hhcl9zejsKICAgICB9
CisgICAgZWxzZSBpZiAoKHAgPSBzdHJfbnRoKHMsIGUsIGJlZywgZW5jLCAwKSkg
PT0gZSkgeworCWxlbiA9IDA7CisgICAgfQogICAgIGVsc2UgewotCWxlbiA9IHN0
cl9vZmZzZXQocCwgZSwgbGVuLCBlbmMsIHNpbmdsZWJ5dGUpOworCWxlbiA9IHN0
cl9vZmZzZXQocCwgZSwgbGVuLCBlbmMsIDApOwogICAgIH0KICAgc3ViOgogICAg
IGlmIChsZW4gPiBSU1RSSU5HX0VNQkVEX0xFTl9NQVggJiYgYmVnICsgbGVuID09
IFJTVFJJTkdfTEVOKHN0cikpIHsK

------------KCp9piFTOi5tPjFIS3F3Sk
Content-Disposition: attachment; filename=split.pat
Content-Type: application/octet-stream; name=split.pat
Content-Transfer-Encoding: Base64

SW5kZXg6IHN0cmluZy5jCj09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09
PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT09PT0KLS0tIHN0cmluZy5j
CShyZXZpc2lvbiAxOTM3NCkKKysrIHN0cmluZy5jCSh3b3JraW5nIGNvcHkpCkBA
IC00OTkxLDcgKzQ5OTEsNyBAQAogICAgIHJiX2VuY29kaW5nICplbmM7CiAgICAg
VkFMVUUgc3BhdDsKICAgICBWQUxVRSBsaW1pdDsKLSAgICBpbnQgYXdrX3NwbGl0
ID0gUWZhbHNlOworICAgIGVudW0ge2F3aywgc3RyaW5nLCByZWdleHB9IHNwbGl0
X3R5cGU7CiAgICAgbG9uZyBiZWcsIGVuZCwgaSA9IDA7CiAgICAgaW50IGxpbSA9
IDA7CiAgICAgV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