[macruby-changes] [2090] MacRuby/branches/experimental/string.c
source_changes at macosforge.org
source_changes at macosforge.org
Sun Jul 26 20:37:50 PDT 2009
Revision: 2090
http://trac.macosforge.org/projects/ruby/changeset/2090
Author: lsansonetti at apple.com
Date: 2009-07-26 20:37:48 -0700 (Sun, 26 Jul 2009)
Log Message:
-----------
fixed indentation + a silly bug
Modified Paths:
--------------
MacRuby/branches/experimental/string.c
Modified: MacRuby/branches/experimental/string.c
===================================================================
--- MacRuby/branches/experimental/string.c 2009-07-27 02:34:08 UTC (rev 2089)
+++ MacRuby/branches/experimental/string.c 2009-07-27 03:37:48 UTC (rev 2090)
@@ -5473,35 +5473,36 @@
return rb_bytestring_length((VALUE)rcv);
}
+static inline long
+bytestring_index(VALUE bstr, VALUE idx)
+{
+ long index = NUM2LONG(idx);
+ while (index < 0) {
+ // adjusting for negative indices
+ index += rb_bytestring_length(bstr);
+ }
+ return index;
+}
+
static VALUE
rb_bytestring_getbyte(VALUE bstr, SEL sel, VALUE idx)
{
- long index = NUM2LONG(idx);
- while(idx < 0)
- {
- // adjusting for negative indices
- idx += rb_bytestring_length(bstr);
- }
- return INT2FIX(rb_bytestring_byte_pointer(bstr)[index]);
+ const long index = bytestring_index(bstr, idx);
+ return INT2FIX(rb_bytestring_byte_pointer(bstr)[index]);
}
static VALUE
rb_bytestring_setbyte(VALUE bstr, SEL sel, VALUE idx, VALUE newbyte)
{
- long index = NUM2LONG(idx);
- while(idx < 0)
- {
- // adjusting for negative indices
- idx += rb_bytestring_length(bstr);
- }
- rb_bytestring_byte_pointer(bstr)[index] = FIX2UINT(newbyte);
- return Qnil;
+ const long index = bytestring_index(bstr, idx);
+ rb_bytestring_byte_pointer(bstr)[index] = FIX2UINT(newbyte);
+ return Qnil;
}
static VALUE
rb_bytestring_bytesize(VALUE bstr, SEL sel)
{
- return LONG2NUM(CFDataGetLength(rb_bytestring_wrapped_data(bstr)));
+ return LONG2NUM(CFDataGetLength(rb_bytestring_wrapped_data(bstr)));
}
static UniChar
@@ -5756,9 +5757,10 @@
rb_bytestring_initialize, -1);
rb_objc_define_method(*(VALUE *)rb_cByteString, "alloc",
rb_bytestring_alloc, 0);
- rb_objc_define_method(rb_cByteString, "bytesize", rb_bytestring_bytesize, 0);
- rb_objc_define_method(rb_cByteString, "getbyte", rb_bytestring_getbyte, 1);
- rb_objc_define_method(rb_cByteString, "setbyte", rb_bytestring_setbyte, 2);
+ rb_objc_define_method(rb_cByteString, "bytesize",
+ rb_bytestring_bytesize, 0);
+ rb_objc_define_method(rb_cByteString, "getbyte", rb_bytestring_getbyte, 1);
+ rb_objc_define_method(rb_cByteString, "setbyte", rb_bytestring_setbyte, 2);
wrappedDataOffset = ivar_getOffset(
class_getInstanceVariable((Class)rb_cByteString,
WRAPPED_DATA_IV_NAME));
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090726/bc6ba6d2/attachment.html>
More information about the macruby-changes
mailing list