[#15707] Schedule for the 1.8.7 release — "Akinori MUSHA" <knu@...>

Hi, developers,

21 messages 2008/03/01

[#15740] Copy-on-write friendly garbage collector — Hongli Lai <hongli@...99.net>

Hi.

31 messages 2008/03/03
[#15742] Re: Copy-on-write friendly garbage collector — Yukihiro Matsumoto <matz@...> 2008/03/03

Hi,

[#15829] Re: Copy-on-write friendly garbage collector — Daniel DeLorme <dan-ml@...42.com> 2008/03/08

Yukihiro Matsumoto wrote:

[#15756] embedding Ruby 1.9.0 inside pthread — "Suraj Kurapati" <sunaku@...>

Hello,

18 messages 2008/03/03
[#15759] Re: embedding Ruby 1.9.0 inside pthread — Nobuyoshi Nakada <nobu@...> 2008/03/04

Hi,

[#15760] Re: embedding Ruby 1.9.0 inside pthread — Yukihiro Matsumoto <matz@...> 2008/03/04

Hi,

[#15762] Re: embedding Ruby 1.9.0 inside pthread — "Suraj N. Kurapati" <sunaku@...> 2008/03/04

Yukihiro Matsumoto wrote:

[#15783] Adding startup and shutdown to Test::Unit — Daniel Berger <Daniel.Berger@...>

Hi all,

15 messages 2008/03/04

[#15835] TimeoutError in core, timeouts for ConditionVariable#wait — MenTaLguY <mental@...>

I've been reworking JRuby's stdlib to improve performance and fix

10 messages 2008/03/09

[#15990] Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...>

Hi,

35 messages 2008/03/23
[#15991] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/23

[#15993] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/23

Hi Dave,

[#15997] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/23

[#16024] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/26

Hi Dave,

[#16025] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16026] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16027] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16029] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16030] Re: Recent changes in Range#step behavior — Yukihiro Matsumoto <matz@...> 2008/03/26

Hi,

[#16031] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16032] Re: Recent changes in Range#step behavior — "Vladimir Sizikov" <vsizikov@...> 2008/03/26

On Wed, Mar 26, 2008 at 7:01 PM, Dave Thomas <dave@pragprog.com> wrote:

[#16033] Re: Recent changes in Range#step behavior — Dave Thomas <dave@...> 2008/03/26

[#16041] Re: Recent changes in Range#step behavior — David Flanagan <david@...> 2008/03/26

Dave Thomas wrote:

Changing the algorithm of String#*

From: apeiros <apeiros@...>
Date: 2008-03-22 20:44:06 UTC
List: ruby-core #15983
Hi there

I recently played around and found String#* to be rather slow,  
wondering why I dug in the source and found it copied only linearly.  
That can be reduced to a logarithmic copying, so I rewrote the code to  
use an algorithm of logarithmic complexity. Please note that my C-fu  
is rather weak, so please peer-review to code.
I hope you deem it worthy to be used in ruby :)
Zenspider btw. pointed out, that the same could be used with Array#*.

The rewritten rb_str_times routine in string.c:

VALUE
rb_str_times(str, times)
   VALUE str;
   VALUE times;
{
   VALUE str2;
   long copy_bytes, ltimes, tmp_len, target_len, rest;

   ltimes = NUM2LONG(times);
   if (ltimes < 0) {
     rb_raise(rb_eArgError, "negative argument");
   }
   if (ltimes && LONG_MAX/ltimes <  RSTRING_LEN(str)) {
     rb_raise(rb_eArgError, "argument too big");
   }

   tmp_len    = (long)pow(2,floor(log2((double)ltimes))) *  
RSTRING_LEN(str);
   target_len = RSTRING_LEN(str) * ltimes;
   rest       = target_len - tmp_len;
   str2       = rb_str_new5(str,0, target_len);
   memcpy(RSTRING_PTR(str2), RSTRING_PTR(str), RSTRING_LEN(str));

   for (copy_bytes = RSTRING_LEN(str); copy_bytes < tmp_len;  
copy_bytes *= 2) {
     memcpy(RSTRING_PTR(str2)+copy_bytes, RSTRING_PTR(str2),  
copy_bytes);
   }
   memcpy(RSTRING_PTR(str2)+copy_bytes, RSTRING_PTR(str2), rest);
   RSTRING_PTR(str2)[RSTRING_LEN(str2)] = '\0';

   OBJ_INFECT(str2, str);

   return str2;
}


Regards
Stefan Rusterholz

In This Thread

Prev Next