From 8ce3f4beeaf99c0e094f7a246613b6439f902e8c Mon Sep 17 00:00:00 2001 From: glass Date: Tue, 9 Jul 2013 03:49:49 +0000 Subject: [PATCH] * io.c (appendline): use READ_CHAR_PENDING_XXX macros and RSTRING_END(). * io.c (rb_io_getline_1): rewrite nested if statement into one statement. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41850 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ io.c | 34 ++++++++++++++-------------------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/ChangeLog b/ChangeLog index 49d3f1e530..c07ec7938a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Tue Jul 9 12:47:08 2013 Masaki Matsushita + + * io.c (appendline): use READ_CHAR_PENDING_XXX macros and + RSTRING_END(). + + * io.c (rb_io_getline_1): rewrite nested if statement into one + statement. + Tue Jul 9 11:04:35 2013 NAKAMURA Usaku * ext/{dl,fiddle}/win32/lib/win32/registry.rb (Win32::Regstry#check): diff --git a/io.c b/io.c index 1a3f998914..3cb39d9c9e 100644 --- a/io.c +++ b/io.c @@ -2760,9 +2760,8 @@ appendline(rb_io_t *fptr, int delim, VALUE *strp, long *lp) do { const char *p, *e; int searchlen; - if (fptr->cbuf.len) { - p = fptr->cbuf.ptr+fptr->cbuf.off; - searchlen = fptr->cbuf.len; + if (searchlen = READ_CHAR_PENDING_COUNT(fptr)) { + p = READ_CHAR_PENDING_PTR(fptr); if (0 < limit && limit < searchlen) searchlen = (int)limit; e = memchr(p, delim, searchlen); @@ -3037,7 +3036,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io) if (c == newline) { if (RSTRING_LEN(str) < rslen) continue; s = RSTRING_PTR(str); - e = s + RSTRING_LEN(str); + e = RSTRING_END(str); p = e - rslen; pp = rb_enc_left_char_head(s, p, e, enc); if (pp != p) continue; @@ -3046,7 +3045,7 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io) } if (limit == 0) { s = RSTRING_PTR(str); - p = s + RSTRING_LEN(str); + p = RSTRING_END(str); pp = rb_enc_left_char_head(s, p-1, p, enc); if (extra_limit && MBCLEN_NEEDMORE_P(rb_enc_precise_mbclen(pp, p, enc))) { @@ -3062,25 +3061,20 @@ rb_io_getline_1(VALUE rs, long limit, VALUE io) } } - if (rspara) { - if (c != EOF) { - swallow(fptr, '\n'); - } - } + if (rspara && c != EOF) + swallow(fptr, '\n'); if (!NIL_P(str)) str = io_enc_str(str, fptr); } - if (!NIL_P(str)) { - if (!nolimit) { - fptr->lineno++; - if (io == ARGF.current_file) { - ARGF.lineno++; - ARGF.last_lineno = ARGF.lineno; - } - else { - ARGF.last_lineno = fptr->lineno; - } + if (!NIL_P(str) && !nolimit) { + fptr->lineno++; + if (io == ARGF.current_file) { + ARGF.lineno++; + ARGF.last_lineno = ARGF.lineno; + } + else { + ARGF.last_lineno = fptr->lineno; } }