[macruby-changes] [5093] MacRuby/trunk/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Dec 30 01:59:52 PST 2010
Revision: 5093
http://trac.macosforge.org/projects/ruby/changeset/5093
Author: vincent.isambart at gmail.com
Date: 2010-12-30 01:59:48 -0800 (Thu, 30 Dec 2010)
Log Message:
-----------
String#* should now be much faster
Modified Paths:
--------------
MacRuby/trunk/string.c
Modified: MacRuby/trunk/string.c
===================================================================
--- MacRuby/trunk/string.c 2010-12-28 13:34:51 UTC (rev 5092)
+++ MacRuby/trunk/string.c 2010-12-30 09:59:48 UTC (rev 5093)
@@ -2331,16 +2331,17 @@
static VALUE
rstr_times(VALUE self, SEL sel, VALUE times)
{
- const long len = NUM2LONG(times);
- if (len < 0) {
+ const long n = NUM2LONG(times);
+ if (n < 0) {
rb_raise(rb_eArgError, "negative argument");
}
- if (len > 0 && LONG_MAX/len < str_length(RSTR(self))) {
+ if (n > 0 && LONG_MAX/n < RSTR(self)->length_in_bytes) {
rb_raise(rb_eArgError, "argument too big");
}
VALUE new = str_new_like(self);
- for (long i = 0; i < len; i++) {
+ str_resize_bytes(RSTR(new), n * RSTR(self)->length_in_bytes);
+ for (long i = 0; i < n; ++i) {
str_concat_string(RSTR(new), RSTR(self));
}
OBJ_INFECT(new, self);
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20101230/7ac25202/attachment.html>
More information about the macruby-changes
mailing list