[macruby-changes] [4198] MacRuby/trunk/io.c
source_changes at macosforge.org
source_changes at macosforge.org
Thu Jun 3 13:02:34 PDT 2010
Revision: 4198
http://trac.macosforge.org/projects/ruby/changeset/4198
Author: pthomson at apple.com
Date: 2010-06-03 13:02:32 -0700 (Thu, 03 Jun 2010)
Log Message:
-----------
small efficiency fix for IO#sysread.
Modified Paths:
--------------
MacRuby/trunk/io.c
Modified: MacRuby/trunk/io.c
===================================================================
--- MacRuby/trunk/io.c 2010-06-03 18:56:39 UTC (rev 4197)
+++ MacRuby/trunk/io.c 2010-06-03 20:02:32 UTC (rev 4198)
@@ -1104,24 +1104,20 @@
}
if (!NIL_P(buffer)) {
- buffer = rb_obj_as_string(buffer);
+ // TODO: throw an error if the provided string can't be modified in place
+ buffer = rb_str_bstr(rb_obj_as_string(buffer));
}
+ else {
+ buffer = rb_bstr_new();
+ }
+ rb_bstr_resize(buffer, to_read);
- uint8_t *bytes = xmalloc(to_read);
+ uint8_t *bytes = rb_bstr_bytes(buffer);
if (read(io->read_fd, bytes, (size_t)to_read) == -1) {
- bytes = NULL;
rb_sys_fail("read(2) failed.");
}
-
- VALUE fresh = rb_bstr_new_with_data(bytes, to_read);
- if (NIL_P(buffer)) {
- buffer = fresh;
- }
- else {
- str_replace_with_string(str_need_string(buffer), str_need_string(fresh));
- }
- bytes = NULL;
+
return buffer;
}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20100603/f45d21c2/attachment-0001.html>
More information about the macruby-changes
mailing list