From 89301d683e7401cb7cfcb6ebc89be6593d4c809f Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Tue, 6 Jun 2000 16:53:06 +0000 Subject: [PATCH] Update. 2000-06-06 Ulrich Drepper * iconvdata/iso-2022-kr.c: Add __builtin_expect in many places. * iconvdata/iso-2022-jp.c: Likewise. * iconvdata/iso-2022-cn.c: Likewise. * iconvdata/gbgbk.c: Likewise. * iconvdata/gbk.c: Likewise. * iconvdata/euc-kr.c: Likewise. * iconvdata/euc-jp.c: Likewise. * iconvdata/euc-cn.c: Likewise. --- ChangeLog | 11 ++++++ iconvdata/euc-cn.c | 13 ++++--- iconvdata/euc-jp.c | 17 +++++---- iconvdata/euc-kr.c | 15 +++++--- iconvdata/gbgbk.c | 21 +++++++---- iconvdata/gbk.c | 14 ++++--- iconvdata/iso-2022-cn.c | 56 ++++++++++++++-------------- iconvdata/iso-2022-jp.c | 82 ++++++++++++++++++++++++----------------- iconvdata/iso-2022-kr.c | 28 +++++++------- 9 files changed, 148 insertions(+), 109 deletions(-) diff --git a/ChangeLog b/ChangeLog index a10b231f52..a960af80e0 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2000-06-06 Ulrich Drepper + + * iconvdata/iso-2022-kr.c: Add __builtin_expect in many places. + * iconvdata/iso-2022-jp.c: Likewise. + * iconvdata/iso-2022-cn.c: Likewise. + * iconvdata/gbgbk.c: Likewise. + * iconvdata/gbk.c: Likewise. + * iconvdata/euc-kr.c: Likewise. + * iconvdata/euc-jp.c: Likewise. + * iconvdata/euc-cn.c: Likewise. + 2000-06-05 Ulrich Drepper * iconvdata/big5hkscs.c: Add __builtin_expect in many places. diff --git a/iconvdata/euc-cn.c b/iconvdata/euc-cn.c index 3211b57642..b4c1725eea 100644 --- a/iconvdata/euc-cn.c +++ b/iconvdata/euc-cn.c @@ -44,7 +44,8 @@ if (ch <= 0x7f) \ ++inptr; \ else \ - if ((ch <= 0xa0 && ch != 0x8e && ch != 0x8f) || ch > 0xfe) \ + if ((__builtin_expect (ch, 0xa1) <= 0xa0 && ch != 0x8e && ch != 0x8f) \ + || __builtin_expect (ch, 0xfe) > 0xfe) \ { \ /* This is illegal. */ \ if (! ignore_errors_p ()) \ @@ -63,7 +64,7 @@ next character is also available. */ \ const unsigned char *endp; \ \ - if (NEED_LENGTH_TEST && inptr + 1 >= inend) \ + if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0)) \ { \ /* The second character is not available. Store \ the intermediate result. */ \ @@ -74,7 +75,7 @@ ch = inptr[1]; \ \ /* All second bytes of a multibyte character must be >= 0xa1. */ \ - if (ch < 0xa1) \ + if (__builtin_expect (ch, 0xa1) < 0xa1) \ { \ if (! ignore_errors_p ()) \ { \ @@ -92,7 +93,7 @@ endp = inptr; \ \ ch = gb2312_to_ucs4 (&endp, 2, 0x80); \ - if (ch == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ /* This is an illegal character. */ \ if (! ignore_errors_p ()) \ @@ -135,9 +136,9 @@ found = ucs4_to_gb2312 (ch, outptr, \ (NEED_LENGTH_TEST \ ? outend - outptr : MAX_NEEDED_OUTPUT)); \ - if (!NEED_LENGTH_TEST || found != 0) \ + if (!NEED_LENGTH_TEST || __builtin_expect (found, 1) != 0) \ { \ - if (found == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (found, 0) == __UNKNOWN_10646_CHAR) \ { \ /* Illegal character. */ \ if (! ignore_errors_p ()) \ diff --git a/iconvdata/euc-jp.c b/iconvdata/euc-jp.c index 240d76037f..a781182e78 100644 --- a/iconvdata/euc-jp.c +++ b/iconvdata/euc-jp.c @@ -46,7 +46,8 @@ \ if (ch <= 0x7f) \ ++inptr; \ - else if ((ch <= 0xa0 && ch != 0x8e && ch != 0x8f) || ch > 0xfe) \ + else if ((__builtin_expect (ch, 0xa1) <= 0xa0 && ch != 0x8e && ch != 0x8f)\ + || __builtin_expect (ch, 0xfe) > 0xfe) \ { \ /* This is illegal. */ \ if (! ignore_errors_p ()) \ @@ -65,7 +66,7 @@ character is also available. */ \ int ch2; \ \ - if (NEED_LENGTH_TEST && inptr + 1 >= inend) \ + if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0)) \ { \ /* The second character is not available. Store the \ intermediate result. */ \ @@ -76,7 +77,7 @@ ch2 = inptr[1]; \ \ /* All second bytes of a multibyte character must be >= 0xa1. */ \ - if (ch2 < 0xa1) \ + if (__builtin_expect (ch2, 0xa1) < 0xa1) \ { \ /* This is an illegal character. */ \ if (! ignore_errors_p ()) \ @@ -119,13 +120,13 @@ 0x80); \ } \ \ - if (NEED_LENGTH_TEST && ch == 0) \ + if (NEED_LENGTH_TEST && __builtin_expect (ch, 1) == 0) \ { \ /* Not enough input available. */ \ result = __GCONV_INCOMPLETE_INPUT; \ break; \ } \ - if (ch == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ /* Illegal character. */ \ if (! ignore_errors_p ()) \ @@ -173,7 +174,7 @@ size_t found; \ \ /* See whether we have room for at least two characters. */ \ - if (NEED_LENGTH_TEST && outptr + 1 >= outend) \ + if (NEED_LENGTH_TEST && __builtin_expect (outptr + 1 >= outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -204,13 +205,13 @@ (NEED_LENGTH_TEST \ ? outend - outptr - 1 : 2)); \ \ - if (found == 0) \ + if (__builtin_expect (found, 1) == 0) \ { \ /* We ran out of space. */ \ result = __GCONV_FULL_OUTPUT; \ break; \ } \ - else if (found != __UNKNOWN_10646_CHAR) \ + else if (__builtin_expect (found, 0) != __UNKNOWN_10646_CHAR) \ { \ /* It's a JIS 0212 character, adjust it for EUC-JP. */ \ *outptr++ = 0x8f; \ diff --git a/iconvdata/euc-kr.c b/iconvdata/euc-kr.c index d84e72ca5d..48fdee3cdc 100644 --- a/iconvdata/euc-kr.c +++ b/iconvdata/euc-kr.c @@ -28,7 +28,8 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp) { if (ch > 0x7f) { - if (ucs4_to_ksc5601 (ch, cp, 2) != __UNKNOWN_10646_CHAR) + if (__builtin_expect (ucs4_to_ksc5601 (ch, cp, 2), 0) + != __UNKNOWN_10646_CHAR) { cp[0] |= 0x80; cp[1] |= 0x80; @@ -78,7 +79,9 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp) ++inptr; \ /* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \ user-defined areas. */ \ - else if (ch <= 0xa0 || ch > 0xfe || ch == 0xc9) \ + else if (__builtin_expect (ch, 0xa1) <= 0xa0 \ + || __builtin_expect (ch, 0xa1) > 0xfe \ + || __builtin_expect (ch, 0xa1) == 0xc9) \ { \ /* This is illegal. */ \ if (! ignore_errors_p ()) \ @@ -97,13 +100,13 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp) is also available. */ \ ch = ksc5601_to_ucs4 (&inptr, \ NEED_LENGTH_TEST ? inptr - inend : 2, 0x80); \ - if (NEED_LENGTH_TEST && ch == 0) \ + if (NEED_LENGTH_TEST && __builtin_expect (ch, 1) == 0) \ { \ /* The second character is not available. */ \ result = __GCONV_INCOMPLETE_INPUT; \ break; \ } \ - if (ch == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ /* This is an illegal character. */ \ if (! ignore_errors_p ()) \ @@ -139,7 +142,7 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp) Jamos should be considered either here or in euckr_from_ucs4() */ \ euckr_from_ucs4 (ch, cp) ; \ \ - if (cp[0] == '\0' && ch != 0) \ + if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \ { \ /* Illegal character. */ \ if (! ignore_errors_p ()) \ @@ -157,7 +160,7 @@ euckr_from_ucs4 (uint32_t ch, unsigned char *cp) /* Now test for a possible second byte and write this if possible. */ \ if (cp[1] != '\0') \ { \ - if (NEED_LENGTH_TEST && outptr >= outend) \ + if (NEED_LENGTH_TEST && __builtin_expect (outptr >= outend, 0)) \ { \ /* The result does not fit into the buffer. */ \ --outptr; \ diff --git a/iconvdata/gbgbk.c b/iconvdata/gbgbk.c index 88617ae6c0..9a3e385cba 100644 --- a/iconvdata/gbgbk.c +++ b/iconvdata/gbgbk.c @@ -71,7 +71,7 @@ UCS4 -> GB2312 -> GBK -> UCS4 \ \ might not produce identical text. */ \ - if (NEED_LENGTH_TEST && inptr + 1 >= inend) \ + if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0)) \ { \ /* The second character is not available. Store \ the intermediate result. */ \ @@ -79,7 +79,7 @@ break; \ } \ \ - if (NEED_LENGTH_TEST && outend - outptr < 2) \ + if (NEED_LENGTH_TEST && __builtin_expect (outend - outptr < 2, 0)) \ { \ /* We ran out of space. */ \ result = __GCONV_FULL_OUTPUT; \ @@ -89,11 +89,16 @@ ch = (ch << 8) | inptr[1]; \ \ /* Now determine whether the character is valid. */ \ - if (ch < 0xa1a1 || ch > 0xf7fe || inptr[1] < 0xa1 \ + if (__builtin_expect (ch, 0xa1a1) < 0xa1a1 \ + || __builtin_expect (ch, 0xa1a1) > 0xf7fe \ + || __builtin_expect (inptr[1], 0xa1) < 0xa1 \ /* Now test the exceptions. */ \ - || (ch >= 0xa2a1 && ch <= 0xa2aa) \ - || (ch >= 0xa6e0 && ch <= 0xa6f5) \ - || (ch >= 0xa8bb && ch <= 0xa8c0)) \ + || (__builtin_expect (ch, 0xa1a1) >= 0xa2a1 \ + && __builtin_expect (ch, 0xa1a1) <= 0xa2aa) \ + || (__builtin_expect (ch, 0xa1a1) >= 0xa6e0 \ + && __builtin_expect (ch, 0xa1a1) <= 0xa6f5) \ + || (__builtin_expect (ch, 0xa1a1) >= 0xa8bb \ + && __builtin_expect (ch, 0xa1a1) <= 0xa8c0)) \ { \ /* One of the characters we cannot map. */ \ if (! ignore_errors_p ()) \ @@ -131,7 +136,7 @@ \ if (ch > 0x7f) \ { \ - if (NEED_LENGTH_TEST && inptr + 1 >= inend) \ + if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0)) \ { \ /* The second character is not available. Store \ the intermediate result. */ \ @@ -139,7 +144,7 @@ break; \ } \ \ - if (NEED_LENGTH_TEST && outend - outptr < 2) \ + if (NEED_LENGTH_TEST && __builtin_expect (outend - outptr < 2, 0)) \ { \ /* We ran out of space. */ \ result = __GCONV_FULL_OUTPUT; \ diff --git a/iconvdata/gbk.c b/iconvdata/gbk.c index c120df08a1..405a3f8b23 100644 --- a/iconvdata/gbk.c +++ b/iconvdata/gbk.c @@ -13121,7 +13121,8 @@ static const char __gbk_from_ucs4_tab12[][2] = if (ch <= 0x7f) \ ++inptr; \ else \ - if (ch <= 0x80 || ch > 0xfe) \ + if (__builtin_expect (ch, 0x81) <= 0x80 \ + || __builtin_expect (ch, 0x81) > 0xfe) \ { \ /* This is illegal. */ \ if (! ignore_errors_p ()) \ @@ -13141,7 +13142,7 @@ static const char __gbk_from_ucs4_tab12[][2] = uint32_t ch2; \ int idx; \ \ - if (NEED_LENGTH_TEST && inptr + 1 >= inend) \ + if (NEED_LENGTH_TEST && __builtin_expect (inptr + 1 >= inend, 0)) \ { \ /* The second character is not available. Store \ the intermediate result. */ \ @@ -13152,7 +13153,7 @@ static const char __gbk_from_ucs4_tab12[][2] = ch2 = inptr[1]; \ \ /* All second bytes of a multibyte character must be >= 0x40. */ \ - if (ch2 < 0x40) \ + if (__builtin_expect (ch2, 0x41) < 0x40) \ { \ /* This is an illegal character. */ \ if (! ignore_errors_p ()) \ @@ -13172,7 +13173,7 @@ static const char __gbk_from_ucs4_tab12[][2] = \ ch = __gbk_to_ucs[idx]; \ \ - if (ch == 0 && *inptr != '\0') \ + if (__builtin_expect (ch, 1) == 0 && *inptr != '\0') \ { \ /* This is an illegal character. */ \ if (! ignore_errors_p ()) \ @@ -13446,7 +13447,7 @@ static const char __gbk_from_ucs4_tab12[][2] = cp = ""; \ break; \ } \ - if (cp == NULL || (cp[0] == '\0' && ch != 0)) \ + if (__builtin_expect (cp[0], '\1') == '\0' && ch != 0) \ { \ /* Illegal character. */ \ if (! ignore_errors_p ()) \ @@ -13458,7 +13459,8 @@ static const char __gbk_from_ucs4_tab12[][2] = ++*converted; \ } \ /* See whether there is enough room for the second byte we write. */ \ - else if (NEED_LENGTH_TEST && cp[1] != '\0' && outptr + 1 >= outend) \ + else if (NEED_LENGTH_TEST && cp[1] != '\0' \ + && __builtin_expect (outptr + 1 >= outend, 0)) \ { \ /* We have not enough room. */ \ result = __GCONV_FULL_OUTPUT; \ diff --git a/iconvdata/iso-2022-cn.c b/iconvdata/iso-2022-cn.c index c89fc5776e..69f5e176e4 100644 --- a/iconvdata/iso-2022-cn.c +++ b/iconvdata/iso-2022-cn.c @@ -86,15 +86,13 @@ enum \ /* We are not in the initial state. To switch back we have \ to emit `SI'. */ \ - if (outbuf == data->__outbufend) \ + if (__builtin_expect (outbuf == data->__outbufend, 0)) \ /* We don't have enough room in the output buffer. */ \ status = __GCONV_FULL_OUTPUT; \ else \ { \ /* Write out the shift sequence. */ \ *outbuf++ = SI; \ - if (data->__flags & __GCONV_IS_LAST) \ - *written += 1; \ data->__outbuf = outbuf; \ data->__statep->__count = ASCII_set; \ } \ @@ -121,7 +119,7 @@ enum uint32_t ch = *inptr; \ \ /* This is a 7bit character set, disallow all 8bit characters. */ \ - if (ch > 0x7f) \ + if (__builtin_expect (ch, 0) > 0x7f) \ { \ if (! ignore_errors_p ()) \ { \ @@ -135,7 +133,7 @@ enum } \ \ /* Recognize escape sequences. */ \ - if (ch == ESC) \ + if (__builtin_expect (ch, 0) == ESC) \ { \ /* There are two kinds of escape sequences we have to handle: \ - those announcing the use of GB and CNS characters on the \ @@ -143,12 +141,15 @@ enum - the initial byte of the SS2 sequence. \ */ \ if (NEED_LENGTH_TEST \ - && (inptr + 1 > inend \ + && (__builtin_expect (inptr + 1 > inend, 0) \ || (inptr[1] == '$' \ - && (inptr + 2 > inend \ - || (inptr[2] == ')' && inptr + 3 > inend) \ - || (inptr[2] == '*' && inptr + 3 > inend))) \ - || (inptr[1] == SS2_1 && inptr + 3 > inend))) \ + && (__builtin_expect (inptr + 2 > inend, 0) \ + || (inptr[2] == ')' \ + && __builtin_expect (inptr + 3 > inend, 0)) \ + || (inptr[2] == '*' \ + && __builtin_expect (inptr + 3 > inend, 0)))) \ + || (inptr[1] == SS2_1 \ + && __builtin_expect (inptr + 3 > inend, 0)))) \ { \ result = __GCONV_EMPTY_INPUT; \ break; \ @@ -166,7 +167,7 @@ enum continue; \ } \ } \ - else if (ch == SO) \ + else if (__builtin_expect (ch, 0) == SO) \ { \ /* Switch to use GB2312 or CNS 11643 plane 1, depending on which \ S0 designation came last. The only problem is what to do with \ @@ -177,7 +178,7 @@ enum set = ann == CNS11643_1_ann ? CNS11643_1_set : GB2312_set; \ continue; \ } \ - else if (ch == SI) \ + else if (__builtin_expect (ch, 0) == SI) \ { \ /* Switch to use ASCII. */ \ ++inptr; \ @@ -185,14 +186,14 @@ enum continue; \ } \ \ - if (ch == ESC && inptr[1] == SS2_1) \ + if (__builtin_expect (ch, 0) == ESC && inptr[1] == SS2_1) \ { \ /* This is a character from CNS 11643 plane 2. \ XXX We could test here whether the use of this character \ set was announced. */ \ inptr += 2; \ ch = cns11643l2_to_ucs4 (&inptr, 2, 0); \ - if (ch == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ if (! ignore_errors_p ()) \ { \ @@ -224,12 +225,12 @@ enum NEED_LENGTH_TEST ? inend - inptr : 2, 0);\ } \ \ - if (NEED_LENGTH_TEST && ch == 0) \ + if (NEED_LENGTH_TEST && __builtin_expect (ch, 1) == 0) \ { \ result = __GCONV_EMPTY_INPUT; \ break; \ } \ - else if (ch == __UNKNOWN_10646_CHAR) \ + else if (__builtin_expect (ch, 1) == __UNKNOWN_10646_CHAR) \ { \ if (! ignore_errors_p ()) \ { \ @@ -261,10 +262,7 @@ enum #define LOOPFCT TO_LOOP #define BODY \ { \ - uint32_t ch; \ - size_t written = 0; \ - \ - ch = get32 (inptr); \ + uint32_t ch = get32 (inptr); \ \ /* First see whether we can write the character using the currently \ selected character set. */ \ @@ -274,7 +272,7 @@ enum { \ *outptr++ = SI; \ set = ASCII_set; \ - if (NEED_LENGTH_TEST && outptr == outend) \ + if (NEED_LENGTH_TEST && __builtin_expet (outptr == outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -282,7 +280,6 @@ enum } \ \ *outptr++ = ch; \ - written = 1; \ \ /* At the end of the line we have to clear the `ann' flags since \ every line must contain this information again. */ \ @@ -293,6 +290,7 @@ enum { \ char buf[2]; \ int used; \ + size_t written = 0; \ \ if (set == GB2312_set || (ann & CNS11643_1_ann) == 0) \ { \ @@ -321,7 +319,7 @@ enum else \ written = ucs4_to_gb2312 (ch, buf, 2); \ \ - if (written != __UNKNOWN_10646_CHAR) \ + if (__builin_expect (written, 0) != __UNKNOWN_10646_CHAR) \ /* Oh well, then switch SO. */ \ used = GB2312_set + CNS11643_1_set - set; \ else \ @@ -350,7 +348,8 @@ enum { \ const char *escseq; \ \ - if (NEED_LENGTH_TEST && outptr + 4 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 4 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -373,7 +372,7 @@ enum \ if (used == CNS11643_2_set) \ { \ - if (outptr + 2 > outend) \ + if (__builtin_expect (outptr + 2 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -388,7 +387,7 @@ enum SO charset. */ \ if (set == ASCII_set) \ { \ - if (outptr + 1 > outend) \ + if (__builtin_expect (outptr + 1 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -399,13 +398,14 @@ enum \ /* Always test the length here since we have used up all the \ guaranteed output buffer slots. */ \ - if (outptr + 2 > outend) \ + if (__builtin_expect (outptr + 2 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ } \ } \ - else if (NEED_LENGTH_TEST && outptr + 2 > outend) \ + else if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 2 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ diff --git a/iconvdata/iso-2022-jp.c b/iconvdata/iso-2022-jp.c index 51420fb43f..25ca75c2df 100644 --- a/iconvdata/iso-2022-jp.c +++ b/iconvdata/iso-2022-jp.c @@ -141,7 +141,7 @@ gconv_init (struct __gconv_step *step) } result = __GCONV_NOCONV; - if (dir != illegal_dir) + if (__builtin_expect (dir, from_iso2022jp) != illegal_dir) { new_data = (struct iso2022jp_data *) malloc (sizeof (struct iso2022jp_data)); @@ -208,7 +208,7 @@ gconv_end (struct __gconv_step *data) \ /* We are not in the initial state. To switch back we have \ to emit the sequence `Esc ( B'. */ \ - if (outbuf + 3 > data->__outbufend) \ + if (__builtin_expect (outbuf + 3 > data->__outbufend, 0)) \ /* We don't have enough room in the output buffer. */ \ status = __GCONV_FULL_OUTPUT; \ else \ @@ -217,8 +217,6 @@ gconv_end (struct __gconv_step *data) *outbuf++ = ESC; \ *outbuf++ = '('; \ *outbuf++ = 'B'; \ - if (data->__flags & __GCONV_IS_LAST) \ - *written += 3; \ data->__outbuf = outbuf; \ /* Note that this also clears the G2 designation. */ \ data->__statep->__count &= ~7; \ @@ -247,16 +245,16 @@ gconv_end (struct __gconv_step *data) uint32_t ch = *inptr; \ \ /* Recognize escape sequences. */ \ - if (ch == ESC) \ + if (__builtin_expect (ch, 0) == ESC) \ { \ /* We now must be prepared to read two to three more \ chracters. If we have a match in the first character but \ then the input buffer ends we terminate with an error since \ we must not risk missing an escape sequence just because it \ is not entirely in the current input buffer. */ \ - if (inptr + 2 >= inend \ + if (__builtin_expect (inptr + 2 >= inend, 0) \ || (var == iso2022jp2 && inptr[1] == '$' && inptr[2] == '(' \ - && inptr + 3 >= inend)) \ + && __builtin_expect (inptr + 3 >= inend, 0))) \ { \ /* Not enough input available. */ \ result = __GCONV_EMPTY_INPUT; \ @@ -357,7 +355,7 @@ gconv_end (struct __gconv_step *data) ch = inptr[2] | 0x80; \ inptr += 3; \ } \ - else if (set2 == ISO88597_set) \ + else if (__builtin_expect (set2, ISO88597_set) == ISO88597_set) \ { \ /* We use the table from the ISO 8859-7 module. */ \ if (inptr[2] < 0x20 || inptr[2] > 0x80) \ @@ -407,7 +405,7 @@ gconv_end (struct __gconv_step *data) { \ /* Use the JIS X 0201 table. */ \ ch = jisx0201_to_ucs4 (ch); \ - if (ch == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ if (! ignore_errors_p ()) \ { \ @@ -425,7 +423,7 @@ gconv_end (struct __gconv_step *data) { \ /* Use the JIS X 0201 table. */ \ ch = jisx0201_to_ucs4 (ch + 0x80); \ - if (ch == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ if (! ignore_errors_p ()) \ { \ @@ -465,12 +463,12 @@ gconv_end (struct __gconv_step *data) NEED_LENGTH_TEST ? inend - inptr : 2, 0); \ } \ \ - if (NEED_LENGTH_TEST && ch == 0) \ + if (NEED_LENGTH_TEST && __builtin_expect (ch, 1) == 0) \ { \ result = __GCONV_EMPTY_INPUT; \ break; \ } \ - else if (ch == __UNKNOWN_10646_CHAR) \ + else if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ if (! ignore_errors_p ()) \ { \ @@ -575,7 +573,7 @@ gconv_end (struct __gconv_step *data) ? outend - outptr : 2)); \ } \ \ - if (NEED_LENGTH_TEST && written == 0) \ + if (NEED_LENGTH_TEST && __builtin_expect (written, 1) == 0) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -633,7 +631,7 @@ gconv_end (struct __gconv_step *data) { \ /* We must encode using ASCII. First write out the \ escape sequence. */ \ - if (NEED_LENGTH_TEST && outptr + 3 > outend) \ + if (NEED_LENGTH_TEST && __builtin_expect (outptr + 3 > outend, 0))\ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -644,7 +642,7 @@ gconv_end (struct __gconv_step *data) *outptr++ = 'B'; \ set = ASCII_set; \ \ - if (NEED_LENGTH_TEST && outptr + 1 > outend) \ + if (NEED_LENGTH_TEST && __builtin_expect (outptr + 1 > outend, 0))\ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -668,7 +666,8 @@ gconv_end (struct __gconv_step *data) if (written != __UNKNOWN_10646_CHAR && buf[0] < 0x80) \ { \ /* We use JIS X 0201. */ \ - if (NEED_LENGTH_TEST && outptr + 3 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 3 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -679,7 +678,8 @@ gconv_end (struct __gconv_step *data) *outptr++ = 'J'; \ set = JISX0201_Roman_set; \ \ - if (NEED_LENGTH_TEST && outptr + 1 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 1 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -692,7 +692,8 @@ gconv_end (struct __gconv_step *data) if (written != __UNKNOWN_10646_CHAR) \ { \ /* We use JIS X 0208. */ \ - if (NEED_LENGTH_TEST && outptr + 3 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 3 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -703,7 +704,8 @@ gconv_end (struct __gconv_step *data) *outptr++ = 'B'; \ set = JISX0208_1983_set; \ \ - if (NEED_LENGTH_TEST && outptr + 2 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 2 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -711,7 +713,7 @@ gconv_end (struct __gconv_step *data) *outptr++ = buf[0]; \ *outptr++ = buf[1]; \ } \ - else if (var == iso2022jp) \ + else if (__builtin_expect (var, iso2022jp2) == iso2022jp) \ { \ /* We have no other choice. */ \ if (! ignore_errors_p ()) \ @@ -728,7 +730,8 @@ gconv_end (struct __gconv_step *data) if (written != __UNKNOWN_10646_CHAR) \ { \ /* We use JIS X 0212. */ \ - if (NEED_LENGTH_TEST && outptr + 4 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 4 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -739,7 +742,8 @@ gconv_end (struct __gconv_step *data) *outptr++ = 'D'; \ set = JISX0212_set; \ \ - if (NEED_LENGTH_TEST && outptr + 2 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 2 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -754,7 +758,8 @@ gconv_end (struct __gconv_step *data) && buf[0] >= 0x80) \ { \ /* We use JIS X 0201. */ \ - if (NEED_LENGTH_TEST && outptr + 3 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 3 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -765,7 +770,8 @@ gconv_end (struct __gconv_step *data) *outptr++ = 'I'; \ set = JISX0201_Kana_set; \ \ - if (NEED_LENGTH_TEST && outptr + 1 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 1 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -775,7 +781,8 @@ gconv_end (struct __gconv_step *data) else if (ch != 0xa5 && ch >= 0x80 && ch <= 0xff) \ { \ /* ISO 8859-1 upper half. */ \ - if (NEED_LENGTH_TEST && outptr + 3 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 3 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -786,7 +793,8 @@ gconv_end (struct __gconv_step *data) *outptr++ = 'A'; \ set2 = ISO88591_set; \ \ - if (NEED_LENGTH_TEST && outptr + 3 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 3 > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -801,7 +809,9 @@ gconv_end (struct __gconv_step *data) if (written != __UNKNOWN_10646_CHAR) \ { \ /* We use GB 2312. */ \ - if (NEED_LENGTH_TEST && outptr + 3 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 3 > outend, \ + 0) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -812,7 +822,9 @@ gconv_end (struct __gconv_step *data) *outptr++ = 'A'; \ set = GB2312_set; \ \ - if (NEED_LENGTH_TEST && outptr + 2 > outend) \ + if (NEED_LENGTH_TEST \ + && __builtin_expect (outptr + 2 > outend, \ + 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -827,7 +839,8 @@ gconv_end (struct __gconv_step *data) { \ /* We use KSC 5601. */ \ if (NEED_LENGTH_TEST \ - && outptr + 4 > outend) \ + && __builtin_expect (outptr + 4 \ + > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -839,7 +852,8 @@ gconv_end (struct __gconv_step *data) set = KSC5601_set; \ \ if (NEED_LENGTH_TEST \ - && outptr + 2 > outend) \ + && __builtin_expect (outptr + 2 \ + > outend, 0)) \ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -860,11 +874,12 @@ gconv_end (struct __gconv_step *data) gch = iso88597_from_ucs4[ch]; \ } \ \ - if (gch != 0) \ + if (__builtin_expect (gch, 1) != 0) \ { \ /* We use ISO 8859-7 greek. */ \ if (NEED_LENGTH_TEST \ - && outptr + 3 > outend) \ + && __builtin_expect (outptr + 3 \ + > outend, 0))\ { \ result = __GCONV_FULL_OUTPUT; \ break; \ @@ -875,7 +890,8 @@ gconv_end (struct __gconv_step *data) set2 = ISO88597_set; \ \ if (NEED_LENGTH_TEST \ - && outptr + 3 > outend) \ + && __builtin_expect (outptr + 3 \ + > outend, 0))\ { \ result = __GCONV_FULL_OUTPUT; \ break; \ diff --git a/iconvdata/iso-2022-kr.c b/iconvdata/iso-2022-kr.c index e6db8c441a..c4ef73e299 100644 --- a/iconvdata/iso-2022-kr.c +++ b/iconvdata/iso-2022-kr.c @@ -88,15 +88,13 @@ enum \ /* We are not in the initial state. To switch back we have \ to emit `SI'. */ \ - if (outbuf == data->__outbufend) \ + if (__builtin_expect (outbuf == data->__outbufend, 0)) \ /* We don't have enough room in the output buffer. */ \ status = __GCONV_FULL_OUTPUT; \ else \ { \ /* Write out the shift sequence. */ \ *outbuf++ = SI; \ - if (data->__flags & __GCONV_IS_LAST) \ - *written += 1; \ data->__outbuf = outbuf; \ data->__statep->__count = ASCII_set; \ } \ @@ -123,7 +121,7 @@ enum uint32_t ch = *inptr; \ \ /* This is a 7bit character set, disallow all 8bit characters. */ \ - if (ch > 0x7f) \ + if (__builtin_expect (ch, 0) > 0x7f) \ { \ if (! ignore_errors_p ()) \ { \ @@ -137,16 +135,18 @@ enum } \ \ /* Recognize escape sequences. */ \ - if (ch == ESC) \ + if (__builtin_expect (ch, 0) == ESC) \ { \ /* We don't really have to handle escape sequences since all the \ switching is done using the SI and SO bytes. But we have to \ recognize `Esc $ ) C' since this is a kind of flag for this \ encoding. We simply ignore it. */ \ - if ((NEED_LENGTH_TEST && inptr + 1 > inend) \ + if ((NEED_LENGTH_TEST && __builtin_expect (inptr + 1 > inend, 0)) \ || (inptr[1] == '$' \ - && ((NEED_LENGTH_TEST && inptr + 2 > inend) \ - || (inptr[2] == ')' && inptr + 3 > inend)))) \ + && ((NEED_LENGTH_TEST \ + && __builtin_expect (inptr + 2 > inend, 0)) \ + || (inptr[2] == ')' \ + && __builtin_expect (inptr + 3 > inend, 0))))) \ \ { \ result = __GCONV_EMPTY_INPUT; \ @@ -159,14 +159,14 @@ enum continue; \ } \ } \ - else if (ch == SO) \ + else if (__builtin_expect (ch, 0) == SO) \ { \ /* Switch to use KSC. */ \ ++inptr; \ set = KSC5601_set; \ continue; \ } \ - else if (ch == SI) \ + else if (__builtin_expect (ch, 0) == SI) \ { \ /* Switch to use ASCII. */ \ ++inptr; \ @@ -187,12 +187,12 @@ enum ch = ksc5601_to_ucs4 (&inptr, \ NEED_LENGTH_TEST ? inend - inptr : 2, 0); \ \ - if (NEED_LENGTH_TEST && ch == 0) \ + if (NEED_LENGTH_TEST && __builtin_expect (ch, 1) == 0) \ { \ result = __GCONV_EMPTY_INPUT; \ break; \ } \ - else if (ch == __UNKNOWN_10646_CHAR) \ + else if (__builtin_expect (ch, 0) == __UNKNOWN_10646_CHAR) \ { \ if (! ignore_errors_p ()) \ { \ @@ -252,7 +252,7 @@ enum \ written = ucs4_to_ksc5601 (ch, buf, 2); \ \ - if (written == __UNKNOWN_10646_CHAR) \ + if (__builtin_expect (written, 0) == __UNKNOWN_10646_CHAR) \ { \ /* Illegal character. */ \ if (! ignore_errors_p ()) \ @@ -274,7 +274,7 @@ enum set = KSC5601_set; \ } \ \ - if (NEED_LENGTH_TEST && outptr + 2 > outend) \ + if (NEED_LENGTH_TEST && __builtin_expect (outptr + 2 > outend, 0))\ { \ result = __GCONV_FULL_OUTPUT; \ break; \