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