]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - iconvdata/tcvn5712-1.c
Use glibc_likely instead __builtin_expect.
[thirdparty/glibc.git] / iconvdata / tcvn5712-1.c
index bcf002fb88b8dc0e290837aa6d471ccba50dc3d7..21e1d4540a07904945d62b16924cccc23aba2c02 100644 (file)
@@ -1,5 +1,5 @@
 /* Conversion to and from TCVN5712-1.
-   Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+   Copyright (C) 2001-2014 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
 
@@ -14,9 +14,8 @@
    Lesser General Public License for more details.
 
    You should have received a copy of the GNU Lesser General Public
-   License along with the GNU C Library; if not, write to the Free
-   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
-   02111-1307 USA.  */
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
 
 #include <dlfcn.h>
 #include <stdint.h>
 #define TO_LOOP                        to_tcvn5712_1
 #define DEFINE_INIT            1
 #define DEFINE_FINI            1
-#define MIN_NEEDED_FROM                1
-#define MAX_NEEDED_FROM                2
-#define MIN_NEEDED_TO          4
-#define MAX_NEEDED_TO          8
+#define FROM_LOOP_MIN_NEEDED_FROM      1
+#define FROM_LOOP_MAX_NEEDED_FROM      1
+#define FROM_LOOP_MIN_NEEDED_TO                4
+#define FROM_LOOP_MAX_NEEDED_TO                4
+#define TO_LOOP_MIN_NEEDED_FROM                4
+#define TO_LOOP_MAX_NEEDED_FROM                4
+#define TO_LOOP_MIN_NEEDED_TO          1
+#define TO_LOOP_MAX_NEEDED_TO          2
 #define PREPARE_LOOP \
   int saved_state;                                                           \
   int *statep = &data->__statep->__count;
     {                                                                        \
       if (FROM_DIRECTION)                                                    \
        {                                                                     \
-         if (__builtin_expect (outbuf + 4 <= outend, 1))                     \
+         if (__glibc_likely (outbuf + 4 <= outend))                          \
            {                                                                 \
              /* Write out the last character.  */                            \
-             *((uint32_t *) outbuf)++ = data->__statep->__count >> 3;        \
+             *((uint32_t *) outbuf) = data->__statep->__count >> 3;          \
+             outbuf += sizeof (uint32_t);                                    \
              data->__statep->__count = 0;                                    \
            }                                                                 \
          else                                                                \
@@ -153,7 +157,7 @@ static const struct
     { 0x01AF, 0x1EEA },
     { 0x01B0, 0x1EEB },
 #define COMP_TABLE_IDX_0301 (COMP_TABLE_IDX_0300 + COMP_TABLE_LEN_0300)
-#define COMP_TABLE_LEN_0301 51
+#define COMP_TABLE_LEN_0301 50
     { 0x0041, 0x00C1 },
     { 0x0043, 0x0106 },
     { 0x0045, 0x00C9 },
@@ -188,8 +192,7 @@ static const struct
     { 0x0077, 0x1E83 },
     { 0x0079, 0x00FD },
     { 0x007A, 0x017A },
-    { 0x00A5, 0x0385 },
-  /*{ 0x00A8, 0x1FEE },*/
+  /*{ 0x00A8, 0x0385 },*//* prefer U+0385 over U+1FEE */
     { 0x00C2, 0x1EA4 },
   /*{ 0x00C5, 0x01FA },*/
   /*{ 0x00C6, 0x01FC },*/
@@ -356,10 +359,10 @@ static const struct
 
 
 /* First define the conversion function from TCVN5712-1 to UCS4.  */
-#define MIN_NEEDED_INPUT       MIN_NEEDED_FROM
-#define MAX_NEEDED_INPUT       MAX_NEEDED_FROM
-#define MIN_NEEDED_OUTPUT      MIN_NEEDED_TO
-#define MAX_NEEDED_OUTPUT      MAX_NEEDED_TO
+#define MIN_NEEDED_INPUT       FROM_LOOP_MIN_NEEDED_FROM
+#define MAX_NEEDED_INPUT       FROM_LOOP_MAX_NEEDED_FROM
+#define MIN_NEEDED_OUTPUT      FROM_LOOP_MIN_NEEDED_TO
+#define MAX_NEEDED_OUTPUT      FROM_LOOP_MAX_NEEDED_TO
 #define LOOPFCT                        FROM_LOOP
 #define BODY \
   {                                                                          \
@@ -376,7 +379,7 @@ static const struct
     last_ch = *statep >> 3;                                                  \
                                                                              \
     /* We have to buffer ch if it is a possible match in comp_table_data.  */ \
-    must_buffer_ch = (ch >= 0x0041 && ch <= 0x01b0);                         \
+    must_buffer_ch = (ch >= 0x0041 && ch <= 0x01b0);                          \
                                                                              \
     if (last_ch)                                                             \
       {                                                                              \
@@ -470,10 +473,24 @@ static const struct
     ++inptr;                                                                 \
   }
 #define EXTRA_LOOP_DECLS       , int *statep
+#define ONEBYTE_BODY \
+  {                                                                          \
+    uint32_t ch;                                                             \
+                                                                             \
+    if (c < 0x18)                                                            \
+      ch = map_from_tcvn_low[c];                                             \
+    else if (c >= 0x80)                                                              \
+      ch = map_from_tcvn_high[c - 0x80];                                     \
+    else                                                                     \
+      ch = c;                                                                \
+    if (ch >= 0x0041 && ch <= 0x01b0)                                        \
+      return WEOF;                                                           \
+    return ch;                                                               \
+  }
 #include <iconv/loop.c>
 
 
-/* Next, define the conversion function from UCS4 to CP1258.  */
+/* Next, define the conversion function from UCS4 to TCVN5712-1.  */
 
 static const unsigned char from_ucs4[] =
   {
@@ -599,9 +616,10 @@ static const struct
 
 
 /* Next, define the other direction.  */
-#define MIN_NEEDED_INPUT       MIN_NEEDED_TO
-#define MIN_NEEDED_OUTPUT      MIN_NEEDED_FROM
-#define MAX_NEEDED_OUTPUT      MAX_NEEDED_FROM
+#define MIN_NEEDED_INPUT       TO_LOOP_MIN_NEEDED_FROM
+#define MAX_NEEDED_INPUT       TO_LOOP_MAX_NEEDED_FROM
+#define MIN_NEEDED_OUTPUT      TO_LOOP_MIN_NEEDED_TO
+#define MAX_NEEDED_OUTPUT      TO_LOOP_MAX_NEEDED_TO
 #define LOOPFCT                        TO_LOOP
 #define BODY \
   {                                                                          \
@@ -634,7 +652,7 @@ static const struct
            res = 0;                                                          \
          }                                                                   \
                                                                              \
-       if (__builtin_expect (res != 0, 1))                                   \
+       if (__glibc_likely (res != 0))                                        \
          {                                                                   \
            *outptr++ = res;                                                  \
            inptr += 4;                                                       \
@@ -678,7 +696,7 @@ static const struct
                  }                                                           \
                                                                              \
                /* See whether we have room for two bytes.  */                \
-               if (__builtin_expect (outptr + 1 >= outend, 0))               \
+               if (__glibc_unlikely (outptr + 1 >= outend))                  \
                  {                                                           \
                    result = __GCONV_FULL_OUTPUT;                             \
                    break;                                                    \
@@ -693,7 +711,7 @@ static const struct
                                                                              \
          failed:                                                             \
            /* This is an illegal character.  */                              \
-           STANDARD_ERR_HANDLER (4);                                         \
+           STANDARD_TO_LOOP_ERR_HANDLER (4);                                 \
          }                                                                   \
       }                                                                              \
   }