1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* io.c (rb_io_getline_fast): don't care ASCII incompatible encoding.

(prepare_getline_args): generate a newline according to IO encoding
  when necessary.
  (rb_io_getline_1): call rb_io_getline_fast only for ASCII
  compatible encoding.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@15241 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2008-01-25 15:57:32 +00:00
parent 665e571839
commit f4d73e05d4
2 changed files with 44 additions and 33 deletions

View file

@ -1,3 +1,11 @@
Sat Jan 26 00:43:40 2008 Tanaka Akira <akr@fsij.org>
* io.c (rb_io_getline_fast): don't care ASCII incompatible encoding.
(prepare_getline_args): generate a newline according to IO encoding
when necessary.
(rb_io_getline_1): call rb_io_getline_fast only for ASCII
compatible encoding.
Fri Jan 25 21:49:36 2008 Tanaka Akira <akr@fsij.org>
* string.c (rb_str_buf_cat_ascii): use rb_enc_cr_str_buf_cat.
@ -206,7 +214,7 @@ Wed Jan 23 13:39:48 2008 Tanaka Akira <akr@fsij.org>
Wed Jan 23 11:53:26 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* string.c (str_mod_check, str_nth, str_offset): consitfied.
* string.c (str_mod_check, str_nth, str_offset): constified.
* string.c (rb_str_dump): dump in ASCII-8BIT always.
@ -227,7 +235,7 @@ Tue Jan 22 20:58:15 2008 NAKAMURA Usaku <usa@ruby-lang.org>
Tue Jan 22 19:37:16 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* lib/mkmf.rb (create_makefile): lib files shoudn't depend on install
* lib/mkmf.rb (create_makefile): lib files shouldn't depend on install
dir because if the dir is newer than lib files, lib files will be
always copied.
@ -330,7 +338,7 @@ Mon Jan 21 06:40:03 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* transcode_data.h (rb_transcoding): include pointer to rb_transcoder
and auxiliary data.
* transcode_data.h (rb_transcoder): all callback functions shoud have
* transcode_data.h (rb_transcoder): all callback functions should have
their own parameters.
* enc/trans/{japanese,single_byte}.c: constified.
@ -379,7 +387,7 @@ Sun Jan 20 05:12:44 2008 NARUSE, Yui <naruse@ruby-lang.org>
Sun Jan 20 05:03:46 2008 NARUSE, Yui <naruse@ruby-lang.org>
* ascii.c: remove difinition of replica KOI8-U.
* ascii.c: remove definition of replica KOI8-U.
Sun Jan 20 00:33:59 2008 NARUSE, Yui <naruse@ruby-lang.org>
@ -484,7 +492,7 @@ Fri Jan 18 20:19:51 2008 NAKAMURA Usaku <usa@ruby-lang.org>
Fri Jan 18 20:03:05 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/setup.mak (BASERUBY): nmake cannot execute ruby collectly
* win32/setup.mak (BASERUBY): nmake cannot execute ruby correctly
if the path of ruby.exe is quoted.
* win32/setup.mak ($(ARCH)): if a macro is appended by $(APPEND),
@ -701,7 +709,7 @@ Tue Jan 15 18:05:26 2008 NAKAMURA Usaku <usa@ruby-lang.org>
Tue Jan 15 18:01:55 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* win32/Makefile.sub (MKFILES): add dependecies.
* win32/Makefile.sub (MKFILES): add dependencies.
Tue Jan 15 18:00:16 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
@ -741,7 +749,7 @@ Tue Jan 15 13:54:41 2008 NAKAMURA Usaku <usa@ruby-lang.org>
Tue Jan 15 13:43:18 2008 NAKAMURA Usaku <usa@ruby-lang.org>
* common.mk (us_ascii.o): add dependecies. [ruby-dev:33111]
* common.mk (us_ascii.o): add dependencies. [ruby-dev:33111]
Tue Jan 15 03:41:42 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
@ -921,7 +929,7 @@ Sun Jan 13 11:41:11 2008 NARUSE, Yui <naruse@ruby-lang.org>
* ruby.c (proc_options): ditto.
* enc/shift_jis.c, enc/euc_jp.c: fixes for romove from builtin.
* enc/shift_jis.c, enc/euc_jp.c: fixes for remove from builtin.
Sun Jan 13 10:21:40 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
@ -932,7 +940,7 @@ Sun Jan 13 09:58:17 2008 NARUSE, Yui <naruse@ruby-lang.org>
* encoding.c (rb_enc_init): revert removing SJIS.
* enc/sjis.c: move to enc/shift_jis.c, to make encoding name equal to
filename for convinience of loading lib.
filename for convenience of loading lib.
* enc/shift_jis.c: moved from enc/sjis.c.
@ -969,14 +977,14 @@ Sun Jan 13 00:01:07 2008 NARUSE, Yui <naruse@ruby-lang.org>
(Init_Encoding): init encdb.
* enc/ascii.c, enc/us_ascii.c, enc/euc_jp.c, enc/sjis.c:
add replica encoding and encoding alias difinition.
add replica encoding and encoding alias definition.
* common.mk (dist-clean-local): add rule for remvoe encdb.h.
* common.mk (dist-clean-local): add rule for remove encdb.h.
Sat Jan 12 18:27:41 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
* eval.c (rb_define_alloc_func, rb_undef_alloc_func): should
define/undef on a signleton class. [ruby-core:09959]
define/undef on a singleton class. [ruby-core:09959]
Sat Jan 12 12:44:36 2008 NARUSE, Yui <naruse@ruby-lang.org>
@ -1035,7 +1043,7 @@ Fri Jan 11 12:35:56 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
configure.
* lib/rdoc/options.rb (check_diagram): more precise check, darwin
is not Windows but minwg is on it.
is not Windows but mingw is on it.
Fri Jan 11 09:59:05 2008 NARUSE, Yui <naruse@ruby-lang.org>
@ -1095,7 +1103,7 @@ Wed Jan 9 20:55:38 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
Wed Jan 9 20:35:42 2008 GOTOU Yuuzou <gotoyuzo@notwork.org>
* lib/webrick/httprequest.rb: supprt X-Forwarded-* header fields.
* lib/webrick/httprequest.rb: support X-Forwarded-* header fields.
WEBrick::HTTPRequest#{host,port,request_uri} is derived having
regards to X-Forwarded-Proto and X-Forwarded-Host.
@ -1148,7 +1156,7 @@ Wed Jan 9 13:03:34 2008 Yukihiro Matsumoto <matz@ruby-lang.org>
Wed Jan 9 08:42:01 2008 James Edward Gray II <jeg2@ruby-lang.org>
* enum.c: Updating the documentation of Enumrable#zip to reflect
* enum.c: Updating the documentation of Enumerable#zip to reflect
the recent changes Matz made to the method.
Wed Jan 9 01:35:10 2008 NARUSE, Yui <naruse@ruby-lang.org>
@ -2250,7 +2258,7 @@ Tue Dec 25 23:25:29 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
Tue Dec 25 23:16:01 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
* ruby.c (proc_options): encoding option in shbang and RUBYOPT did not
* ruby.c (proc_options): encoding option in shebang and RUBYOPT did not
work, do not store alloca()ed string in a parent scope struct.
Tue Dec 25 22:56:52 2007 NAKAMURA Usaku <usa@ruby-lang.org>
@ -2263,7 +2271,7 @@ Tue Dec 25 22:55:42 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
Tue Dec 25 22:45:10 2007 Koichi Sasada <ko1@atdot.net>
* insns2vm.rb: add encoding option to shbang.
* insns2vm.rb: add encoding option to shebang.
Tue Dec 25 22:13:51 2007 Koichi Sasada <ko1@atdot.net>

33
io.c
View file

@ -1792,27 +1792,17 @@ rb_io_getline_fast(rb_io_t *fptr)
{
VALUE str = Qnil;
int len = 0;
rb_encoding *enc = io_read_encoding(fptr);
for (;;) {
long pending = READ_DATA_PENDING_COUNT(fptr);
if (pending > 0) {
const char *p = READ_DATA_PENDING_PTR(fptr);
const char *pend = p + pending - 1;
const char *e;
e = memchr(p, '\n', pending);
if (e) {
const char *p0 = rb_enc_left_char_head(p, e, enc);
pend = rb_enc_left_char_head(p0, pend, enc);
if (rb_enc_is_newline(p0, pend, enc)) {
pending = p0 - p + rb_enc_mbclen(p0, pend, enc);
}
else {
e = 0;
}
pending = e - p + 1;
}
if (NIL_P(str)) {
str = rb_str_new(p, pending);
@ -1864,7 +1854,7 @@ prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io)
}
}
}
if (!NIL_P(rs) && rs != rb_default_rs) {
if (!NIL_P(rs)) {
rb_encoding *enc_rs, *enc_io;
GetOpenFile(io, fptr);
@ -1873,12 +1863,24 @@ prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io)
if (enc_io != enc_rs &&
(rb_enc_str_coderange(rs) != ENC_CODERANGE_7BIT ||
!rb_enc_asciicompat(enc_io))) {
rb_raise(rb_eArgError, "IO and RS encodings differ");
if (rs == rb_default_rs) {
rs = rb_enc_str_new(0, 0, enc_io);
rb_str_buf_cat_ascii(rs, "\n");
}
else {
rb_raise(rb_eArgError, "encoding mismatch: %s IO with %s RS",
rb_enc_name(enc_io),
rb_enc_name(enc_rs));
}
}
if (fptr->enc2) {
rs = rb_funcall(rs, id_encode, 2,
VALUE rs2;
rs2 = rb_funcall(rs, id_encode, 2,
rb_enc_from_encoding(fptr->enc2),
rb_enc_from_encoding(fptr->enc));
if (!RTEST(rb_str_equal(rs, rs2))) {
rs = rs2;
}
}
}
*rsp = rs;
@ -1903,7 +1905,8 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io)
else if (limit == 0) {
return rb_enc_str_new(0, 0, io_read_encoding(fptr));
}
else if (rs == rb_default_rs && limit < 0) {
else if (rs == rb_default_rs && limit < 0 &&
rb_enc_asciicompat(io_read_encoding(fptr))) {
return rb_io_getline_fast(fptr);
}
else {