[macruby-changes] [1410] MacRuby/branches/experimental
source_changes at macosforge.org
source_changes at macosforge.org
Sun Apr 12 01:01:58 PDT 2009
Revision: 1410
http://trac.macosforge.org/projects/ruby/changeset/1410
Author: lsansonetti at apple.com
Date: 2009-04-12 01:01:57 -0700 (Sun, 12 Apr 2009)
Log Message:
-----------
accelerated parsing IO
Modified Paths:
--------------
MacRuby/branches/experimental/io.c
MacRuby/branches/experimental/parse.y
Modified: MacRuby/branches/experimental/io.c
===================================================================
--- MacRuby/branches/experimental/io.c 2009-04-12 07:58:57 UTC (rev 1409)
+++ MacRuby/branches/experimental/io.c 2009-04-12 08:01:57 UTC (rev 1410)
@@ -919,6 +919,22 @@
return bytestring_buffer;
}
+UInt8 *
+rb_io_read_all_file(VALUE io, size_t *buflen)
+{
+ rb_io_t *io_struct = ExtractIOStruct(io);
+ struct stat buf;
+ if (fstat(io_struct->fd, &buf) == -1) {
+ return NULL;
+ }
+ UInt8 *str = (UInt8 *)xmalloc(buf.st_size);
+ rb_io_read_internal(io_struct, str, buf.st_size);
+ if (buflen != NULL) {
+ *buflen = buf.st_size;
+ }
+ return str;
+}
+
/*
* call-seq:
* ios.readpartial(maxlen) => string
@@ -1139,9 +1155,12 @@
rb_io_gets_m(VALUE io, SEL sel, int argc, VALUE *argv)
{
VALUE sep, limit;
- rb_scan_args(argc, argv, "02", &sep, &limit);
+ sep = limit = Qnil;
+ if (argc != 0) {
+ rb_scan_args(argc, argv, "02", &sep, &limit);
+ }
rb_io_t *io_struct = ExtractIOStruct(io);
- rb_io_assert_readable(io_struct);
+ rb_io_assert_readable(io_struct);
if (rb_io_eof(io, 0) == Qtrue) {
return Qnil;
}
Modified: MacRuby/branches/experimental/parse.y
===================================================================
--- MacRuby/branches/experimental/parse.y 2009-04-12 07:58:57 UTC (rev 1409)
+++ MacRuby/branches/experimental/parse.y 2009-04-12 08:01:57 UTC (rev 1410)
@@ -5116,10 +5116,37 @@
return rb_parser_compile_string(vparser, f, rb_str_new(s, len), line);
}
+struct lex_io_gets_data {
+ UInt8 *buf;
+ size_t buflen;
+};
+
static VALUE
-lex_io_gets(struct parser_params *parser, VALUE io)
+lex_io_gets(struct parser_params *parser, VALUE udata)
{
- return rb_io_gets(io, 0);
+ struct lex_io_gets_data *data = (struct lex_io_gets_data *)udata;
+
+ long beg = 0;
+ if (lex_gets_ptr > 0) {
+ if (data->buflen == lex_gets_ptr) {
+ return Qnil;
+ }
+ beg = lex_gets_ptr;
+ }
+
+ char *p = strchr((char *)data->buf + beg, '\n');
+ if (p != NULL) {
+ const long location = p - (char *)data->buf;
+ lex_gets_ptr = location + 1;
+ }
+ else {
+ lex_gets_ptr = data->buflen;
+ }
+
+ CFStringRef v = CFStringCreateWithBytes(NULL, data->buf + beg,
+ lex_gets_ptr - beg, kCFStringEncodingUTF8, false);
+ CFMakeCollectable(v);
+ return (VALUE)v;
}
NODE*
@@ -5130,6 +5157,8 @@
return rb_parser_compile_file(vparser, f, file, start);
}
+UInt8 *rb_io_read_all_file(VALUE io, size_t *buflen);
+
NODE*
rb_parser_compile_file(volatile VALUE vparser, const char *f, VALUE file, int start)
{
@@ -5138,13 +5167,26 @@
NODE *node;
Data_Get_Struct(vparser, struct parser_params, parser);
+
+ size_t buflen = 0;
+ UInt8 *buf = rb_io_read_all_file(file, &buflen);
+ if (buf == NULL || buflen == 0) {
+ return NULL;
+ }
+
+ struct lex_io_gets_data data;
+ data.buf = buf;
+ data.buflen = buflen;
+
lex_gets = lex_io_gets;
- lex_input = file;
+ lex_input = (VALUE)&data;
lex_pbeg = lex_p = lex_pend = 0;
node = yycompile(parser, f, start);
tmp = vparser; /* prohibit tail call optimization */
+ xfree(buf);
+
return node;
}
#endif /* !RIPPER */
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/macruby-changes/attachments/20090412/a82b3cc8/attachment.html>
More information about the macruby-changes
mailing list