From badd9f1efca296be0f1dce0491f8c7662434da5f Mon Sep 17 00:00:00 2001 From: akr Date: Sun, 10 Aug 2008 13:37:44 +0000 Subject: * transcode.c (transcode_restartable0): invalid handling simplified. (transcode_restartable): use PARTIAL_INPUT for converting buffered input. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18476 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- transcode.c | 48 +++++++++++++++++------------------------------- 1 file changed, 17 insertions(+), 31 deletions(-) (limited to 'transcode.c') diff --git a/transcode.c b/transcode.c index 3c1858d67d..317781b2ac 100644 --- a/transcode.c +++ b/transcode.c @@ -533,40 +533,26 @@ transcode_restartable0(const unsigned char **in_pos, unsigned char **out_pos, break; } case INVALID: - { - if (tc->readlen + (in_p - inchar_start) <= unitlen) { - while ((opt & PARTIAL_INPUT) && tc->readlen + (in_stop - inchar_start) < unitlen) { - in_p = in_stop; - SUSPEND(transcode_ibuf_empty, 8); - } - if (tc->readlen + (in_stop - inchar_start) <= unitlen) { - in_p = in_stop; - } - else { - in_p = inchar_start + (unitlen - tc->readlen); - } + if (tc->readlen + (in_p - inchar_start) <= unitlen) { + while ((opt & PARTIAL_INPUT) && tc->readlen + (in_stop - inchar_start) < unitlen) { + in_p = in_stop; + SUSPEND(transcode_ibuf_empty, 8); + } + if (tc->readlen + (in_stop - inchar_start) <= unitlen) { + in_p = in_stop; } else { - int found_len; /* including the last byte which cuases invalid */ - int invalid_len; - int step; - found_len = tc->readlen + (in_p - inchar_start); - invalid_len = ((found_len - 1) / unitlen) * unitlen; - step = invalid_len - found_len; - if (step < -1) { - if (-step <= in_p - *in_pos) { - in_p += step; - } - else { - feedlen = -step; - } - } - else { - in_p += step; - } + in_p = inchar_start + (unitlen - tc->readlen); } - goto invalid; } + else { + int invalid_len; /* including the last byte which causes invalid */ + int discard_len; + invalid_len = tc->readlen + (in_p - inchar_start); + discard_len = ((invalid_len - 1) / unitlen) * unitlen; + feedlen = invalid_len - discard_len; + } + goto invalid; case UNDEF: goto undef; } @@ -608,7 +594,7 @@ transcode_restartable(const unsigned char **in_pos, unsigned char **out_pos, MEMCPY(feed_buf, TRANSCODING_READBUF(tc) + tc->readlen, unsigned char, tc->feedlen); tc->feedlen = 0; - res = transcode_restartable0(&feed_pos, out_pos, feed_stop, out_stop, tc, opt); + res = transcode_restartable0(&feed_pos, out_pos, feed_stop, out_stop, tc, opt|PARTIAL_INPUT); if (res != transcode_ibuf_empty) { MEMCPY(TRANSCODING_READBUF(tc) + tc->readlen + tc->feedlen, feed_pos, unsigned char, feed_stop - feed_pos); -- cgit v1.2.3